2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <gdk/gdkkeysyms.h>
31 #include <glib/gi18n.h>
33 #include <clutter/clutter.h>
34 #include <clutter-gtk/clutter-gtk.h>
35 #include <clutter-gst/clutter-gst.h>
37 #include <telepathy-glib/util.h>
38 #include <telepathy-farstream/telepathy-farstream.h>
39 #include <telepathy-glib/util.h>
41 #include <farstream/fs-element-added-notifier.h>
42 #include <farstream/fs-utils.h>
44 #include <libempathy/empathy-camera-monitor.h>
45 #include <libempathy/empathy-gsettings.h>
46 #include <libempathy/empathy-tp-contact-factory.h>
47 #include <libempathy/empathy-request-util.h>
48 #include <libempathy/empathy-utils.h>
50 #include <libempathy-gtk/empathy-avatar-image.h>
51 #include <libempathy-gtk/empathy-dialpad-widget.h>
52 #include <libempathy-gtk/empathy-ui-utils.h>
53 #include <libempathy-gtk/empathy-sound-manager.h>
54 #include <libempathy-gtk/empathy-geometry.h>
55 #include <libempathy-gtk/empathy-images.h>
56 #include <libempathy-gtk/empathy-call-utils.h>
58 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
59 #include <libempathy/empathy-debug.h>
61 #include "empathy-call-window.h"
62 #include "empathy-call-window-fullscreen.h"
63 #include "empathy-call-factory.h"
64 #include "empathy-video-widget.h"
65 #include "empathy-about-dialog.h"
66 #include "empathy-audio-src.h"
67 #include "empathy-audio-sink.h"
68 #include "empathy-video-src.h"
69 #include "empathy-mic-menu.h"
70 #include "empathy-preferences.h"
71 #include "empathy-rounded-actor.h"
72 #include "empathy-rounded-rectangle.h"
73 #include "empathy-rounded-texture.h"
74 #include "empathy-camera-menu.h"
76 #define CONTENT_HBOX_BORDER_WIDTH 6
77 #define CONTENT_HBOX_SPACING 3
78 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
80 #define SELF_VIDEO_SECTION_WIDTH 120
81 #define SELF_VIDEO_SECTION_HEIGHT 90
82 #define SELF_VIDEO_SECTION_MARGIN 2
83 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
85 #define FLOATING_TOOLBAR_OPACITY 192
86 #define FLOATING_TOOLBAR_SPACING 20
88 /* The avatar's default width and height are set to the same value because we
89 want a square icon. */
90 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
91 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
92 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
94 #define SMALL_TOOLBAR_SIZE 36
96 /* If an video input error occurs, the error message will start with "v4l" */
97 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
99 /* The time interval in milliseconds between 2 outgoing rings */
100 #define MS_BETWEEN_RING 500
102 /* The roundedness of preview box and placeholders */
103 #define PREVIEW_ROUND_FACTOR 16
105 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
108 PROP_CALL_HANDLER = 1,
112 RINGING, /* Incoming call */
113 CONNECTING, /* Outgoing call */
114 CONNECTED, /* Connected */
115 HELD, /* Connected, but on hold */
116 DISCONNECTED, /* Disconnected */
117 REDIALING /* Redialing (special case of CONNECTING) */
121 CAMERA_STATE_OFF = 0,
127 PREVIEW_POS_TOP_LEFT,
128 PREVIEW_POS_TOP_RIGHT,
129 PREVIEW_POS_BOTTOM_LEFT,
130 PREVIEW_POS_BOTTOM_RIGHT,
133 struct _EmpathyCallWindowPriv
135 gboolean dispose_has_run;
136 EmpathyCallHandler *handler;
138 EmpathyContact *contact;
140 EmpathyCameraMonitor *camera_monitor;
145 GtkUIManager *ui_manager;
146 GtkWidget *errors_vbox;
147 /* widget displays the video received from the remote user. This widget is
148 * alive only during call. */
149 ClutterActor *video_output;
150 ClutterActor *video_preview;
151 ClutterActor *drag_preview;
152 ClutterActor *preview_shown_button;
153 ClutterActor *preview_hidden_button;
154 ClutterActor *preview_rectangle1;
155 ClutterActor *preview_rectangle2;
156 ClutterActor *preview_rectangle3;
157 ClutterActor *preview_rectangle4;
158 ClutterActor *preview_spinner_actor;
159 GtkWidget *preview_spinner_widget;
160 GtkWidget *video_container;
161 GtkWidget *remote_user_avatar_widget;
162 GtkWidget *remote_user_avatar_toolbar;
163 GtkWidget *remote_user_name_toolbar;
164 GtkWidget *remote_user_status_toolbar;
165 GtkWidget *status_label;
166 GtkWidget *hangup_button;
167 GtkWidget *audio_call_button;
168 GtkWidget *video_call_button;
169 GtkWidget *mic_button;
170 GtkWidget *volume_button;
171 GtkWidget *camera_button;
172 GtkWidget *dialpad_button;
174 GtkWidget *bottom_toolbar;
175 ClutterActor *floating_toolbar;
177 GtkAction *menu_fullscreen;
178 GtkAction *menu_swap_camera;
180 ClutterState *transitions;
182 /* The main box covering all the stage, contaning remote avatar/video */
183 ClutterActor *video_box;
184 ClutterLayoutManager *video_layout;
186 /* A Box layout manager containing a bin for previews
187 * and the floating toolbar */
188 ClutterActor *overlay_box;
189 ClutterLayoutManager *overlay_layout;
191 /* Bin layout for the previews */
192 ClutterActor *preview_box;
193 ClutterLayoutManager *preview_layout;
195 /* Coordinates of the preview drag event's start. */
196 PreviewPosition preview_pos;
198 /* We keep a reference on the hbox which contains the main content so we can
199 easilly repack everything when toggling fullscreen */
200 GtkWidget *content_hbox;
202 /* These are used to accept or reject an incoming call when the status
204 GtkWidget *incoming_call_dialog;
205 TpCallChannel *pending_channel;
206 TpChannelDispatchOperation *pending_cdo;
207 TpAddDispatchOperationContext *pending_context;
209 gulong video_output_motion_handler_id;
210 guint bus_message_source_id;
212 GtkWidget *dtmf_panel;
215 GtkWidget *details_vbox;
216 GtkWidget *vcodec_encoding_label;
217 GtkWidget *acodec_encoding_label;
218 GtkWidget *vcodec_decoding_label;
219 GtkWidget *acodec_decoding_label;
221 GtkWidget *audio_remote_candidate_label;
222 GtkWidget *audio_local_candidate_label;
223 GtkWidget *video_remote_candidate_label;
224 GtkWidget *video_local_candidate_label;
225 GtkWidget *video_remote_candidate_info_img;
226 GtkWidget *video_local_candidate_info_img;
227 GtkWidget *audio_remote_candidate_info_img;
228 GtkWidget *audio_local_candidate_info_img;
230 GstElement *video_input;
231 GstElement *video_preview_sink;
232 GstElement *video_output_sink;
233 GstElement *audio_input;
234 GstElement *audio_output;
235 gboolean audio_output_added;
236 GstElement *pipeline;
237 GstElement *video_tee;
247 gboolean call_started;
248 gboolean sending_video;
249 CameraState camera_state;
251 EmpathyCallWindowFullscreen *fullscreen;
252 gboolean is_fullscreen;
257 guint inactivity_src;
259 /* Those fields represent the state of the window before it actually was in
261 gboolean dialpad_was_visible_before_fs;
262 gint original_width_before_fs;
263 gint original_height_before_fs;
265 gint x, y, w, h, dialpad_width;
268 /* TRUE if the call should be started when the pipeline is playing */
269 gboolean start_call_when_playing;
270 /* TRUE if we requested to set the pipeline in the playing state */
271 gboolean pipeline_playing;
273 EmpathySoundManager *sound_mgr;
276 EmpathyMicMenu *mic_menu;
277 EmpathyCameraMenu *camera_menu;
280 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
282 static void empathy_call_window_realized_cb (GtkWidget *widget,
283 EmpathyCallWindow *window);
285 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
286 GdkEvent *event, EmpathyCallWindow *window);
288 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
289 GdkEventWindowState *event, EmpathyCallWindow *window);
291 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
294 static void empathy_call_window_hangup_cb (gpointer object,
295 EmpathyCallWindow *window);
297 static void empathy_call_window_fullscreen_cb (gpointer object,
298 EmpathyCallWindow *window);
300 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
302 static gboolean empathy_call_window_video_button_press_cb (
303 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
305 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
306 GdkEventKey *event, EmpathyCallWindow *window);
308 static gboolean empathy_call_window_video_output_motion_notify (
309 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
311 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
314 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
316 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
317 EmpathyCallWindow *window);
319 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
321 static void empathy_call_window_status_message (EmpathyCallWindow *window,
324 static gboolean empathy_call_window_bus_message (GstBus *bus,
325 GstMessage *message, gpointer user_data);
328 make_background_transparent (GtkClutterActor *actor)
330 GdkRGBA transparent = { 0., 0., 0., 0. };
333 widget = gtk_clutter_actor_get_widget (actor);
334 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
338 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
341 gtk_widget_set_visible (self->priv->hangup_button, show);
342 gtk_widget_set_visible (self->priv->audio_call_button, !show);
343 gtk_widget_set_visible (self->priv->video_call_button, !show);
347 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
348 EmpathyCallWindow *self)
350 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
351 empathy_call_window_restart_call (self);
355 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
356 EmpathyCallWindow *self)
358 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
359 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
360 empathy_call_window_restart_call (self);
364 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
366 EmpathyCallWindow *self)
371 g_object_get (self->priv->handler, "call-channel", &call, NULL);
373 tones[0] = tp_dtmf_event_to_char (event);
375 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
377 g_object_unref (call);
381 empathy_call_window_show_video_output (EmpathyCallWindow *self,
384 if (self->priv->video_output != NULL)
385 g_object_set (self->priv->video_output, "visible", show, NULL);
387 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
389 clutter_actor_raise_top (self->priv->overlay_box);
393 create_video_output_widget (EmpathyCallWindow *self)
395 EmpathyCallWindowPriv *priv = GET_PRIV (self);
397 g_assert (priv->video_output == NULL);
398 g_assert (priv->pipeline != NULL);
400 priv->video_output = clutter_texture_new ();
402 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
405 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
406 if (priv->video_output_sink == NULL)
407 g_error ("Missing cluttersink");
409 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
411 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
414 gtk_widget_add_events (priv->video_container,
415 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
416 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
417 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
421 create_video_input (EmpathyCallWindow *self)
423 EmpathyCallWindowPriv *priv = GET_PRIV (self);
425 g_assert (priv->video_input == NULL);
426 priv->video_input = empathy_video_src_new ();
427 gst_object_ref_sink (priv->video_input);
431 audio_control_volume_to_element (GBinding *binding,
432 const GValue *source_value,
433 GValue *target_value,
436 /* AudioControl volume is 0-255, with -1 for unknown */
439 hv = g_value_get_int (source_value);
444 g_value_set_double (target_value, hv/255.0);
450 element_volume_to_audio_control (GBinding *binding,
451 const GValue *source_value,
452 GValue *target_value,
457 ev = g_value_get_double (source_value);
458 ev = CLAMP (ev, 0.0, 1.0);
460 g_value_set_int (target_value, ev * 255);
465 create_audio_input (EmpathyCallWindow *self)
467 EmpathyCallWindowPriv *priv = GET_PRIV (self);
469 g_assert (priv->audio_input == NULL);
470 priv->audio_input = empathy_audio_src_new ();
471 gst_object_ref_sink (priv->audio_input);
473 g_object_bind_property (priv->mic_button, "active",
474 priv->audio_input, "mute",
475 G_BINDING_BIDIRECTIONAL |
476 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
480 add_video_preview_to_pipeline (EmpathyCallWindow *self)
482 EmpathyCallWindowPriv *priv = GET_PRIV (self);
485 g_assert (priv->video_preview != NULL);
486 g_assert (priv->pipeline != NULL);
487 g_assert (priv->video_input != NULL);
488 g_assert (priv->video_tee != NULL);
490 preview = priv->video_preview_sink;
492 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
494 g_warning ("Could not add video input to pipeline");
498 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
500 g_warning ("Could not add video preview to pipeline");
504 if (!gst_element_link (priv->video_input, priv->video_tee))
506 g_warning ("Could not link video input to video tee");
510 if (!gst_element_link (priv->video_tee, preview))
512 g_warning ("Could not link video tee to video preview");
518 empathy_call_window_disable_camera_cb (GtkAction *action,
519 EmpathyCallWindow *self)
521 clutter_actor_destroy (self->priv->preview_hidden_button);
523 gtk_toggle_tool_button_set_active (
524 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
528 empathy_call_window_minimise_camera_cb (GtkAction *action,
529 EmpathyCallWindow *self)
531 clutter_actor_hide (self->priv->video_preview);
532 clutter_actor_show (self->priv->preview_hidden_button);
536 empathy_call_window_maximise_camera_cb (GtkAction *action,
537 EmpathyCallWindow *self)
539 clutter_actor_show (self->priv->video_preview);
540 clutter_actor_hide (self->priv->preview_hidden_button);
544 empathy_call_window_swap_camera_cb (GtkAction *action,
545 EmpathyCallWindow *self)
547 const GList *cameras, *l;
550 DEBUG ("Swapping the camera");
552 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
553 current_cam = empathy_video_src_dup_device (
554 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
556 for (l = cameras; l != NULL; l = l->next)
558 EmpathyCamera *camera = l->data;
560 if (!tp_strdiff (camera->device, current_cam))
565 next = l->next->data;
567 next = cameras->data;
569 /* EmpathyCameraMenu will update itself and do the actual change
571 g_settings_set_string (self->priv->settings,
572 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
579 g_free (current_cam);
583 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
584 EmpathyCamera *camera,
585 EmpathyCallWindow *self)
587 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
589 gtk_action_set_visible (self->priv->menu_swap_camera,
590 g_list_length ((GList *) cameras) >= 2);
594 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
595 EmpathyCamera *camera,
596 EmpathyCallWindow *self)
598 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
600 gtk_action_set_visible (self->priv->menu_swap_camera,
601 g_list_length ((GList *) cameras) >= 2);
605 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
606 EmpathyCallWindow *self)
610 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
612 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
613 0, gtk_get_current_event_time ());
614 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
618 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
619 EmpathyCallWindow *self)
623 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
624 "/preview-hidden-menu");
625 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
626 0, gtk_get_current_event_time ());
627 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
630 static ClutterActor *
631 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
632 ClutterBinAlignment x,
633 ClutterBinAlignment y)
635 ClutterActor *rectangle;
637 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
638 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
639 PREVIEW_ROUND_FACTOR));
641 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
643 clutter_actor_hide (rectangle);
649 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
653 self->priv->preview_layout = clutter_bin_layout_new (
654 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
655 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
657 clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (self->priv->overlay_layout),
658 box, TRUE, TRUE, TRUE,
659 CLUTTER_BOX_ALIGNMENT_CENTER, CLUTTER_BOX_ALIGNMENT_START);
661 self->priv->preview_rectangle1 =
662 empathy_call_window_create_preview_rectangle (self,
663 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
664 self->priv->preview_rectangle2 =
665 empathy_call_window_create_preview_rectangle (self,
666 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
667 self->priv->preview_rectangle3 =
668 empathy_call_window_create_preview_rectangle (self,
669 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
670 self->priv->preview_rectangle4 =
671 empathy_call_window_create_preview_rectangle (self,
672 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
676 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
679 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
680 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
681 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
682 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
686 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
691 guint ret_x = 0, ret_y = 0;
694 if (!clutter_actor_has_allocation (self->priv->preview_box))
697 clutter_actor_get_geometry (self->priv->preview_box, &box);
701 case PREVIEW_POS_TOP_LEFT:
702 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
704 case PREVIEW_POS_TOP_RIGHT:
705 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
706 - SELF_VIDEO_SECTION_WIDTH;
707 ret_y = SELF_VIDEO_SECTION_MARGIN;
709 case PREVIEW_POS_BOTTOM_LEFT:
710 ret_x = SELF_VIDEO_SECTION_MARGIN;
711 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
712 - SELF_VIDEO_SECTION_HEIGHT;
714 case PREVIEW_POS_BOTTOM_RIGHT:
715 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
716 - SELF_VIDEO_SECTION_WIDTH;
717 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
718 - SELF_VIDEO_SECTION_HEIGHT;
721 g_warn_if_reached ();
732 static PreviewPosition
733 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
738 PreviewPosition pos = PREVIEW_POS_NONE;
740 if (!clutter_actor_has_allocation (self->priv->preview_box))
743 clutter_actor_get_geometry (self->priv->preview_box, &box);
745 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
746 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
747 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
748 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
750 pos = PREVIEW_POS_TOP_LEFT;
752 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
753 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
754 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
755 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
757 pos = PREVIEW_POS_TOP_RIGHT;
759 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
760 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
761 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
762 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
764 pos = PREVIEW_POS_BOTTOM_LEFT;
766 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
767 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
768 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
769 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
771 pos = PREVIEW_POS_BOTTOM_RIGHT;
777 static ClutterActor *
778 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
781 ClutterActor *rectangle;
785 case PREVIEW_POS_TOP_LEFT:
786 rectangle = self->priv->preview_rectangle1;
788 case PREVIEW_POS_TOP_RIGHT:
789 rectangle = self->priv->preview_rectangle3;
791 case PREVIEW_POS_BOTTOM_LEFT:
792 rectangle = self->priv->preview_rectangle2;
794 case PREVIEW_POS_BOTTOM_RIGHT:
795 rectangle = self->priv->preview_rectangle4;
805 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
808 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
810 DEBUG ("moving the video preview to %d", pos);
812 self->priv->preview_pos = pos;
816 case PREVIEW_POS_TOP_LEFT:
817 clutter_bin_layout_set_alignment (layout,
818 self->priv->video_preview,
819 CLUTTER_BIN_ALIGNMENT_START,
820 CLUTTER_BIN_ALIGNMENT_START);
822 case PREVIEW_POS_TOP_RIGHT:
823 clutter_bin_layout_set_alignment (layout,
824 self->priv->video_preview,
825 CLUTTER_BIN_ALIGNMENT_END,
826 CLUTTER_BIN_ALIGNMENT_START);
828 case PREVIEW_POS_BOTTOM_LEFT:
829 clutter_bin_layout_set_alignment (layout,
830 self->priv->video_preview,
831 CLUTTER_BIN_ALIGNMENT_START,
832 CLUTTER_BIN_ALIGNMENT_END);
834 case PREVIEW_POS_BOTTOM_RIGHT:
835 clutter_bin_layout_set_alignment (layout,
836 self->priv->video_preview,
837 CLUTTER_BIN_ALIGNMENT_END,
838 CLUTTER_BIN_ALIGNMENT_END);
841 g_warn_if_reached ();
844 g_settings_set_enum (self->priv->settings, "camera-position", pos);
848 _clutter_color_from_rgba (ClutterColor *color,
851 color->red = (guint8) floor (rgba->red * 255);
852 color->green = (guint8) floor (rgba->green * 255);
853 color->blue = (guint8) floor (rgba->blue * 255);
854 color->alpha = (guint8) floor (rgba->alpha * 255);
858 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
861 ClutterActor *rectangle;
862 GtkStyleContext *context;
864 ClutterColor color, highlight;
866 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
867 context = gtk_widget_get_style_context (GTK_WIDGET (self));
868 gtk_style_context_get_color (context, 0, &rgba);
870 _clutter_color_from_rgba (&color, &rgba);
871 clutter_color_shade (&color, 1.4, &highlight);
873 empathy_rounded_rectangle_set_border_width (
874 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
875 empathy_rounded_rectangle_set_border_color (
876 EMPATHY_ROUNDED_RECTANGLE (rectangle), &highlight);
880 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
881 ClutterActor *rectangle)
883 GtkStyleContext *context;
885 ClutterColor color, darker;
887 context = gtk_widget_get_style_context (GTK_WIDGET (self));
888 gtk_style_context_get_background_color (context, 0, &rgba);
890 _clutter_color_from_rgba (&color, &rgba);
891 clutter_color_shade (&color, 0.55, &darker);
893 empathy_rounded_rectangle_set_border_width (
894 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
895 empathy_rounded_rectangle_set_border_color (
896 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
900 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
902 ClutterActor *rectangle;
904 rectangle = empathy_call_window_get_preview_rectangle (self,
905 self->priv->preview_pos);
907 /* We don't want to darken the rectangle where the preview
910 if (self->priv->preview_rectangle1 != rectangle)
911 empathy_call_window_darken_preview_rectangle (self,
912 self->priv->preview_rectangle1);
914 if (self->priv->preview_rectangle2 != rectangle)
915 empathy_call_window_darken_preview_rectangle (self,
916 self->priv->preview_rectangle2);
918 if (self->priv->preview_rectangle3 != rectangle)
919 empathy_call_window_darken_preview_rectangle (self,
920 self->priv->preview_rectangle3);
922 if (self->priv->preview_rectangle4 != rectangle)
923 empathy_call_window_darken_preview_rectangle (self,
924 self->priv->preview_rectangle4);
928 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
932 ClutterModifierType modifiers,
933 EmpathyCallWindow *self)
935 ClutterActor *stage = clutter_actor_get_stage (actor);
938 self->priv->drag_preview = clutter_clone_new (actor);
940 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
941 self->priv->drag_preview);
943 clutter_actor_transform_stage_point (actor, event_x, event_y,
946 clutter_actor_set_position (self->priv->drag_preview,
947 event_x - rel_x, event_y - rel_y);
949 clutter_drag_action_set_drag_handle (action,
950 self->priv->drag_preview);
952 clutter_actor_set_opacity (actor, 0);
953 clutter_actor_hide (self->priv->preview_shown_button);
955 empathy_call_window_show_preview_rectangles (self, TRUE);
956 empathy_call_window_darken_preview_rectangles (self);
960 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
963 clutter_actor_set_opacity (actor, 255);
967 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
971 ClutterModifierType modifiers,
972 EmpathyCallWindow *self)
977 /* Get the position before destroying the drag actor, otherwise the
978 * preview_box allocation won't be valid and we won't be able to
979 * calculate the position. */
980 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
982 empathy_call_window_get_preview_coordinates (self,
983 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
986 /* Move the preview to the destination and destroy it afterwards */
987 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
990 "signal-swapped-after::completed",
991 clutter_actor_destroy, self->priv->drag_preview,
992 "signal-swapped-after::completed",
993 clutter_actor_show, self->priv->preview_shown_button,
995 empathy_call_window_on_animation_completed_cb, actor,
998 self->priv->drag_preview = NULL;
1000 if (pos != PREVIEW_POS_NONE)
1001 empathy_call_window_move_video_preview (self, pos);
1003 empathy_call_window_show_preview_rectangles (self, FALSE);
1007 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1008 ClutterActor *actor,
1011 EmpathyCallWindow *self)
1013 PreviewPosition pos;
1014 gfloat event_x, event_y;
1016 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1018 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1020 if (pos != PREVIEW_POS_NONE)
1021 empathy_call_window_highlight_preview_rectangle (self, pos);
1023 empathy_call_window_darken_preview_rectangles (self);
1027 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1028 ClutterCrossingEvent *event,
1029 EmpathyCallWindow *self)
1031 ClutterActor *rectangle;
1033 rectangle = empathy_call_window_get_preview_rectangle (self,
1034 self->priv->preview_pos);
1036 empathy_call_window_highlight_preview_rectangle (self,
1037 self->priv->preview_pos);
1039 clutter_actor_show (rectangle);
1045 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1046 ClutterCrossingEvent *event,
1047 EmpathyCallWindow *self)
1049 ClutterActor *rectangle;
1051 rectangle = empathy_call_window_get_preview_rectangle (self,
1052 self->priv->preview_pos);
1054 empathy_call_window_darken_preview_rectangle (self, rectangle);
1056 clutter_actor_hide (rectangle);
1062 create_video_preview (EmpathyCallWindow *self)
1064 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1065 ClutterLayoutManager *layout;
1066 ClutterActor *preview;
1068 ClutterAction *action;
1070 PreviewPosition pos;
1072 g_assert (priv->video_preview == NULL);
1074 pos = g_settings_get_enum (priv->settings, "camera-position");
1076 preview = empathy_rounded_texture_new ();
1077 clutter_actor_set_size (preview,
1078 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1080 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1081 if (priv->video_preview_sink == NULL)
1082 g_error ("Missing cluttersink, check your clutter-gst installation");
1083 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1084 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1086 /* Add a little offset to the video preview */
1087 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1088 CLUTTER_BIN_ALIGNMENT_CENTER);
1089 priv->video_preview = clutter_box_new (layout);
1090 clutter_actor_set_size (priv->video_preview,
1091 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1092 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1094 /* Spinner for when changing the camera device */
1095 priv->preview_spinner_widget = gtk_spinner_new ();
1096 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1098 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1099 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1100 gtk_widget_show (priv->preview_spinner_widget);
1103 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1104 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1105 priv->preview_spinner_widget);
1106 clutter_actor_set_size (priv->preview_spinner_actor,
1107 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1108 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1109 clutter_actor_hide (priv->preview_spinner_actor);
1111 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1113 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1114 priv->preview_spinner_actor);
1116 g_object_set (priv->video_preview_sink,
1121 /* Translators: this is an "Info" label. It should be as short
1123 button = gtk_button_new_with_label (_("i"));
1124 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (button);
1125 clutter_actor_set_size (b, 24, 24);
1126 clutter_actor_set_margin_right (b, 4);
1127 clutter_actor_set_margin_bottom (b, 2);
1128 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1130 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1131 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1133 g_signal_connect (button, "clicked",
1134 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1137 /* Translators: this is an "Info" label. It should be as short
1139 button = gtk_button_new_with_label (_("i"));
1140 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (button);
1141 clutter_actor_set_size (b, 24, 24);
1142 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1144 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1145 priv->preview_hidden_button,
1146 CLUTTER_BIN_ALIGNMENT_START,
1147 CLUTTER_BIN_ALIGNMENT_END);
1149 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1151 clutter_actor_hide (priv->preview_hidden_button);
1153 g_signal_connect (button, "clicked",
1154 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1157 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1158 priv->video_preview,
1159 CLUTTER_BIN_ALIGNMENT_START,
1160 CLUTTER_BIN_ALIGNMENT_END);
1162 empathy_call_window_move_video_preview (self, pos);
1164 action = clutter_drag_action_new ();
1165 g_signal_connect (action, "drag-begin",
1166 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1167 g_signal_connect (action, "drag-end",
1168 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1169 g_signal_connect (action, "drag-motion",
1170 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1172 g_signal_connect (preview, "enter-event",
1173 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1174 g_signal_connect (preview, "leave-event",
1175 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1177 clutter_actor_add_action (preview, action);
1178 clutter_actor_set_reactive (preview, TRUE);
1179 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1183 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1185 clutter_actor_show (self->priv->preview_spinner_actor);
1186 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1190 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1192 clutter_actor_hide (self->priv->preview_spinner_actor);
1193 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1197 empathy_call_window_play_camera (EmpathyCallWindow *self,
1200 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1201 GstElement *preview;
1204 if (priv->video_preview == NULL)
1206 create_video_preview (self);
1207 add_video_preview_to_pipeline (self);
1212 state = GST_STATE_PLAYING;
1216 empathy_call_window_start_camera_spinning (self);
1217 state = GST_STATE_NULL;
1220 preview = priv->video_preview_sink;
1222 gst_element_set_state (preview, state);
1223 gst_element_set_state (priv->video_tee, state);
1224 gst_element_set_state (priv->video_input, state);
1228 display_video_preview (EmpathyCallWindow *self,
1231 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1233 if (priv->video_preview == NULL)
1235 create_video_preview (self);
1236 add_video_preview_to_pipeline (self);
1241 /* Display the video preview */
1242 DEBUG ("Show video preview");
1244 empathy_call_window_play_camera (self, TRUE);
1245 clutter_actor_show (priv->video_preview);
1246 clutter_actor_raise_top (priv->floating_toolbar);
1250 /* Hide the video preview */
1251 DEBUG ("Hide video preview");
1253 if (priv->video_preview != NULL)
1255 clutter_actor_hide (priv->video_preview);
1256 empathy_call_window_play_camera (self, FALSE);
1262 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1264 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1266 empathy_call_window_status_message (window, _("Connecting…"));
1267 priv->call_state = CONNECTING;
1269 /* Show the toolbar */
1270 clutter_state_set_state (priv->transitions, "fade-in");
1273 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1274 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1278 disable_camera (EmpathyCallWindow *self)
1280 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1282 if (priv->camera_state == CAMERA_STATE_OFF)
1285 DEBUG ("Disable camera");
1287 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1289 priv->camera_state = CAMERA_STATE_OFF;
1293 enable_camera (EmpathyCallWindow *self)
1295 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1297 if (priv->camera_state == CAMERA_STATE_ON)
1300 if (priv->video_input == NULL)
1302 DEBUG ("Can't enable camera, no input");
1306 DEBUG ("Enable camera");
1308 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1310 priv->camera_state = CAMERA_STATE_ON;
1314 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1315 EmpathyCallWindow *self)
1317 if (gtk_toggle_tool_button_get_active (toggle))
1318 enable_camera (self);
1320 disable_camera (self);
1324 create_pipeline (EmpathyCallWindow *self)
1326 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1329 g_assert (priv->pipeline == NULL);
1331 priv->pipeline = gst_pipeline_new (NULL);
1332 priv->pipeline_playing = FALSE;
1334 priv->video_tee = gst_element_factory_make ("tee", NULL);
1335 gst_object_ref_sink (priv->video_tee);
1337 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1339 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1340 priv->bus_message_source_id = gst_bus_add_watch (bus,
1341 empathy_call_window_bus_message, self);
1343 g_object_unref (bus);
1347 empathy_call_window_settings_cb (GtkAction *action,
1348 EmpathyCallWindow *self)
1350 gchar *args = g_strdup_printf ("-p %s",
1351 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1353 empathy_launch_program (BIN_DIR, "empathy", args);
1359 empathy_call_window_contents_cb (GtkAction *action,
1360 EmpathyCallWindow *self)
1362 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1366 empathy_call_window_debug_cb (GtkAction *action,
1367 EmpathyCallWindow *self)
1369 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1373 empathy_call_window_about_cb (GtkAction *action,
1374 EmpathyCallWindow *self)
1376 empathy_about_dialog_new (GTK_WINDOW (self));
1380 empathy_call_window_toolbar_timeout (gpointer data)
1382 EmpathyCallWindow *self = data;
1384 /* We don't want to hide the toolbar if we're not in a call, as
1385 * to show the call status all the time. */
1386 if (self->priv->call_state != CONNECTING &&
1387 self->priv->call_state != DISCONNECTED)
1388 clutter_state_set_state (self->priv->transitions, "fade-out");
1394 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1396 EmpathyCallWindow *self)
1398 clutter_state_set_state (self->priv->transitions, "fade-in");
1400 if (self->priv->inactivity_src > 0)
1401 g_source_remove (self->priv->inactivity_src);
1403 self->priv->inactivity_src = g_timeout_add_seconds (3,
1404 empathy_call_window_toolbar_timeout, self);
1410 empathy_call_window_configure_event_cb (GtkWidget *widget,
1412 EmpathyCallWindow *self)
1414 GdkWindow *gdk_window;
1415 GdkWindowState window_state;
1417 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1418 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1420 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1421 &self->priv->dialpad_width, NULL);
1423 gdk_window = gtk_widget_get_window (widget);
1424 window_state = gdk_window_get_state (gdk_window);
1425 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1431 empathy_call_window_destroyed_cb (GtkWidget *object,
1432 EmpathyCallWindow *self)
1434 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1436 /* Save the geometry as if the dialpad was hidden. */
1437 empathy_geometry_save_values (GTK_WINDOW (self),
1438 self->priv->x, self->priv->y,
1439 self->priv->w - self->priv->dialpad_width, self->priv->h,
1440 self->priv->maximized);
1445 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1447 EmpathyCallWindow *self)
1449 switch (response_id)
1451 case GTK_RESPONSE_ACCEPT:
1452 tp_channel_dispatch_operation_handle_with_async (
1453 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1455 tp_clear_object (&self->priv->pending_cdo);
1456 tp_clear_object (&self->priv->pending_channel);
1457 tp_clear_object (&self->priv->pending_context);
1460 case GTK_RESPONSE_CANCEL:
1461 tp_channel_dispatch_operation_close_channels_async (
1462 self->priv->pending_cdo, NULL, NULL);
1464 empathy_call_window_status_message (self, _("Disconnected"));
1465 self->priv->call_state = DISCONNECTED;
1468 g_warn_if_reached ();
1473 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1477 g_assert (self->priv->call_state != CONNECTED);
1479 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1481 empathy_call_window_status_message (self, _("Incoming call"));
1482 self->priv->call_state = RINGING;
1484 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1485 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1486 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1487 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1488 empathy_contact_get_alias (self->priv->contact));
1490 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1491 _("Reject"), GTK_RESPONSE_CANCEL,
1492 _("Answer"), GTK_RESPONSE_ACCEPT,
1495 g_signal_connect (self->priv->incoming_call_dialog, "response",
1496 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1497 gtk_widget_show (self->priv->incoming_call_dialog);
1501 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1505 EmpathyCallWindow *self)
1507 tp_clear_object (&self->priv->pending_cdo);
1508 tp_clear_object (&self->priv->pending_channel);
1509 tp_clear_object (&self->priv->pending_context);
1511 /* We don't know if the incoming call has been accepted or not, so we
1512 * assume it hasn't and if it has, we'll set the proper status when
1513 * we get the new handler. */
1514 empathy_call_window_status_message (self, _("Disconnected"));
1515 self->priv->call_state = DISCONNECTED;
1517 gtk_widget_destroy (self->priv->incoming_call_dialog);
1518 self->priv->incoming_call_dialog = NULL;
1522 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1523 TpCallChannel *channel,
1524 TpChannelDispatchOperation *dispatch_operation,
1525 TpAddDispatchOperationContext *context)
1527 g_assert (self->priv->pending_channel == NULL);
1528 g_assert (self->priv->pending_context == NULL);
1529 g_assert (self->priv->pending_cdo == NULL);
1531 /* Start ringing and delay until the user answers or hangs. */
1532 self->priv->pending_channel = g_object_ref (channel);
1533 self->priv->pending_context = g_object_ref (context);
1534 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1536 g_signal_connect (self->priv->pending_cdo, "invalidated",
1537 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1539 empathy_call_window_set_state_ringing (self);
1540 tp_add_dispatch_operation_context_accept (context);
1544 empathy_call_window_init (EmpathyCallWindow *self)
1546 EmpathyCallWindowPriv *priv;
1548 GtkWidget *top_vbox;
1550 ClutterConstraint *constraint;
1551 ClutterActor *remote_avatar;
1552 GtkStyleContext *context;
1553 GtkCssProvider *provider;
1557 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1558 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1560 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1562 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1563 gui = empathy_builder_get_file (filename,
1564 "call_window_vbox", &top_vbox,
1565 "errors_vbox", &priv->errors_vbox,
1566 "pane", &priv->pane,
1567 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1568 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1569 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1570 "status_label", &priv->status_label,
1571 "audiocall", &priv->audio_call_button,
1572 "videocall", &priv->video_call_button,
1573 "microphone", &priv->mic_button,
1574 "volume", &priv->volume_button,
1575 "camera", &priv->camera_button,
1576 "hangup", &priv->hangup_button,
1577 "dialpad", &priv->dialpad_button,
1578 "toolbar", &priv->toolbar,
1579 "bottom_toolbar", &priv->bottom_toolbar,
1580 "ui_manager", &priv->ui_manager,
1581 "menufullscreen", &priv->menu_fullscreen,
1582 "menupreviewswap", &priv->menu_swap_camera,
1583 "details_vbox", &priv->details_vbox,
1584 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1585 "acodec_encoding_label", &priv->acodec_encoding_label,
1586 "acodec_decoding_label", &priv->acodec_decoding_label,
1587 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1588 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1589 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1590 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1591 "video_local_candidate_label", &priv->video_local_candidate_label,
1592 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1593 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1594 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1595 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1599 empathy_builder_connect (gui, self,
1600 "hangup", "clicked", empathy_call_window_hangup_cb,
1601 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1602 "videocall", "clicked", empathy_call_window_video_call_cb,
1603 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1604 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1605 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1606 "menusettings", "activate", empathy_call_window_settings_cb,
1607 "menucontents", "activate", empathy_call_window_contents_cb,
1608 "menudebug", "activate", empathy_call_window_debug_cb,
1609 "menuabout", "activate", empathy_call_window_about_cb,
1610 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1611 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1612 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1613 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1616 /* FIXME: we should use a stock "OSD" style class for the toolbar,
1617 * once it's available in GTK+/Adwaita.
1619 provider = gtk_css_provider_new ();
1620 gtk_css_provider_load_from_data (provider,
1621 "#CallFloatingToolbar { border-radius: 6px; }", -1, NULL);
1622 gtk_style_context_add_provider (
1623 gtk_widget_get_style_context (priv->bottom_toolbar),
1624 GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1625 g_object_unref (provider);
1627 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1629 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1631 g_object_bind_property (priv->camera_monitor, "available",
1632 priv->camera_button, "sensitive",
1633 G_BINDING_SYNC_CREATE);
1635 g_signal_connect (priv->camera_monitor, "added",
1636 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1637 g_signal_connect (priv->camera_monitor, "removed",
1638 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1640 priv->lock = g_mutex_new ();
1642 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1644 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1645 CONTENT_HBOX_SPACING);
1646 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1647 CONTENT_HBOX_BORDER_WIDTH);
1648 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1651 /* main contents remote avatar/video box */
1652 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1653 CLUTTER_BIN_ALIGNMENT_CENTER);
1655 priv->video_box = clutter_box_new (priv->video_layout);
1657 priv->video_container = gtk_clutter_embed_new ();
1659 gtk_widget_set_size_request (priv->video_container,
1660 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1662 /* Set the background color to that of the rest of the window */
1663 context = gtk_widget_get_style_context (priv->content_hbox);
1664 gtk_style_context_get_background_color (context,
1665 GTK_STATE_FLAG_NORMAL, &rgba);
1666 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1667 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1668 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1669 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1670 clutter_stage_set_color (
1671 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1672 GTK_CLUTTER_EMBED (priv->video_container))),
1675 clutter_container_add (
1676 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1677 GTK_CLUTTER_EMBED (priv->video_container))),
1681 constraint = clutter_bind_constraint_new (
1682 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1683 CLUTTER_BIND_SIZE, 0);
1684 clutter_actor_add_constraint (priv->video_box, constraint);
1686 priv->remote_user_avatar_widget = gtk_image_new ();
1687 remote_avatar = gtk_clutter_actor_new_with_contents (
1688 priv->remote_user_avatar_widget);
1690 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1693 /* create the overlay box */
1694 priv->overlay_layout = clutter_box_layout_new ();
1695 clutter_box_layout_set_vertical (
1696 CLUTTER_BOX_LAYOUT (priv->overlay_layout), TRUE);
1697 priv->overlay_box = clutter_box_new (priv->overlay_layout);
1699 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1701 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1703 empathy_call_window_create_preview_rectangles (self);
1705 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1706 priv->video_container, TRUE, TRUE,
1707 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1709 create_pipeline (self);
1710 create_video_output_widget (self);
1711 create_audio_input (self);
1712 create_video_input (self);
1714 priv->floating_toolbar = gtk_clutter_actor_new ();
1715 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1716 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1718 gtk_widget_reparent (priv->bottom_toolbar,
1719 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1721 clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (priv->overlay_layout),
1722 priv->floating_toolbar, FALSE, FALSE, FALSE,
1723 CLUTTER_BOX_ALIGNMENT_CENTER, CLUTTER_BOX_ALIGNMENT_END);
1725 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1727 clutter_actor_raise_top (priv->floating_toolbar);
1729 /* Transitions for the floating toolbar */
1730 priv->transitions = clutter_state_new ();
1732 /* all transitions last for 2s */
1733 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1735 /* transition from any state to "fade-out" state */
1736 clutter_state_set (priv->transitions, NULL, "fade-out",
1737 priv->floating_toolbar,
1738 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1741 /* transition from any state to "fade-in" state */
1742 clutter_state_set (priv->transitions, NULL, "fade-in",
1743 priv->floating_toolbar,
1744 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1747 /* put the actor into the "fade-in" state with no animation */
1748 clutter_state_warp_to_state (priv->transitions, "fade-in");
1750 /* The call will be started as soon the pipeline is playing */
1751 priv->start_call_when_playing = TRUE;
1753 priv->dtmf_panel = empathy_dialpad_widget_new ();
1754 g_signal_connect (priv->dtmf_panel, "start-tone",
1755 G_CALLBACK (dtmf_start_tone_cb), self);
1757 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1760 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1763 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1765 gtk_widget_show_all (top_vbox);
1767 gtk_widget_hide (priv->dtmf_panel);
1768 gtk_widget_hide (priv->details_vbox);
1770 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1772 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1773 priv->video_container);
1775 /* We hide the bottom toolbar after 3s of inactivity and show it
1776 * again on mouse movement */
1777 priv->inactivity_src = g_timeout_add_seconds (3,
1778 empathy_call_window_toolbar_timeout, self);
1780 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1781 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1783 g_signal_connect (G_OBJECT (self), "realize",
1784 G_CALLBACK (empathy_call_window_realized_cb), self);
1786 g_signal_connect (G_OBJECT (self), "delete-event",
1787 G_CALLBACK (empathy_call_window_delete_cb), self);
1789 g_signal_connect (G_OBJECT (self), "window-state-event",
1790 G_CALLBACK (empathy_call_window_state_event_cb), self);
1792 g_signal_connect (G_OBJECT (self), "key-press-event",
1793 G_CALLBACK (empathy_call_window_key_press_cb), self);
1795 g_signal_connect (self, "motion-notify-event",
1796 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1798 priv->timer = g_timer_new ();
1800 g_object_ref (priv->ui_manager);
1801 g_object_unref (gui);
1803 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1804 priv->mic_menu = empathy_mic_menu_new (self);
1805 priv->camera_menu = empathy_camera_menu_new (self);
1807 empathy_call_window_show_hangup_button (self, TRUE);
1809 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1810 /* These signals are used to track the window position and save it
1811 * when the window is destroyed. We need to do this as we don't want
1812 * the window geometry to be saved with the dialpad taken into account. */
1813 g_signal_connect (self, "destroy",
1814 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1815 g_signal_connect (self, "configure-event",
1816 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1817 g_signal_connect (self, "window-state-event",
1818 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1820 /* Don't display labels in both toolbars */
1821 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1824 /* Instead of specifying a width and a height, we specify only one size. That's
1825 because we want a square avatar icon. */
1827 init_contact_avatar_with_size (EmpathyContact *contact,
1828 GtkWidget *image_widget,
1831 GdkPixbuf *pixbuf_avatar = NULL;
1833 if (contact != NULL)
1835 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1839 if (pixbuf_avatar == NULL)
1841 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1842 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1845 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1847 if (pixbuf_avatar != NULL)
1848 g_object_unref (pixbuf_avatar);
1852 set_window_title (EmpathyCallWindow *self)
1854 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1857 if (priv->contact != NULL)
1859 /* translators: Call is a noun and %s is the contact name. This string
1860 * is used in the window title */
1861 tmp = g_strdup_printf (_("Call with %s"),
1862 empathy_contact_get_alias (priv->contact));
1863 gtk_window_set_title (GTK_WINDOW (self), tmp);
1868 g_warning ("Unknown remote contact!");
1873 set_remote_user_name (EmpathyCallWindow *self,
1874 EmpathyContact *contact)
1876 const gchar *alias = empathy_contact_get_alias (contact);
1877 const gchar *status = empathy_contact_get_status (contact);
1879 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1881 if (status != NULL) {
1884 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1885 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1889 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1895 contact_name_changed_cb (EmpathyContact *contact,
1897 EmpathyCallWindow *self)
1899 set_window_title (self);
1900 set_remote_user_name (self, contact);
1904 contact_presence_changed_cb (EmpathyContact *contact,
1906 EmpathyCallWindow *self)
1908 set_remote_user_name (self, contact);
1912 contact_avatar_changed_cb (EmpathyContact *contact,
1914 EmpathyCallWindow *self)
1917 GtkAllocation allocation;
1918 GtkWidget *avatar_widget;
1920 avatar_widget = self->priv->remote_user_avatar_widget;
1922 gtk_widget_get_allocation (avatar_widget, &allocation);
1923 size = allocation.height;
1927 /* the widget is not allocated yet, set a default size */
1928 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1929 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1932 init_contact_avatar_with_size (contact, avatar_widget, size);
1934 avatar_widget = self->priv->remote_user_avatar_toolbar;
1936 gtk_widget_get_allocation (avatar_widget, &allocation);
1937 size = allocation.height;
1941 /* the widget is not allocated yet, set a default size */
1942 size = SMALL_TOOLBAR_SIZE;
1945 init_contact_avatar_with_size (contact, avatar_widget, size);
1949 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1950 EmpathyCallHandler *handler)
1952 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1954 tp_g_signal_connect_object (priv->contact, "notify::name",
1955 G_CALLBACK (contact_name_changed_cb), self, 0);
1956 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1957 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1958 tp_g_signal_connect_object (priv->contact, "notify::presence",
1959 G_CALLBACK (contact_presence_changed_cb), self, 0);
1961 set_window_title (self);
1962 set_remote_user_name (self, priv->contact);
1964 init_contact_avatar_with_size (priv->contact,
1965 priv->remote_user_avatar_widget,
1966 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1967 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1969 init_contact_avatar_with_size (priv->contact,
1970 priv->remote_user_avatar_toolbar,
1971 SMALL_TOOLBAR_SIZE);
1973 /* The remote avatar is shown by default and will be hidden when we receive
1974 video from the remote side. */
1975 clutter_actor_hide (priv->video_output);
1976 gtk_widget_show (priv->remote_user_avatar_widget);
1980 update_send_codec (EmpathyCallWindow *self,
1983 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1990 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1991 widget = priv->acodec_encoding_label;
1995 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1996 widget = priv->vcodec_encoding_label;
2002 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2003 gtk_label_set_text (GTK_LABEL (widget), tmp);
2008 send_audio_codec_notify_cb (GObject *object,
2012 EmpathyCallWindow *self = user_data;
2014 update_send_codec (self, TRUE);
2018 send_video_codec_notify_cb (GObject *object,
2022 EmpathyCallWindow *self = user_data;
2024 update_send_codec (self, FALSE);
2028 update_recv_codec (EmpathyCallWindow *self,
2031 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2034 GString *str = NULL;
2038 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2039 widget = priv->acodec_decoding_label;
2043 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2044 widget = priv->vcodec_decoding_label;
2050 for (l = codecs; l != NULL; l = g_list_next (l))
2052 FsCodec *codec = l->data;
2055 str = g_string_new (NULL);
2057 g_string_append (str, ", ");
2059 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2063 gtk_label_set_text (GTK_LABEL (widget), str->str);
2064 g_string_free (str, TRUE);
2068 recv_audio_codecs_notify_cb (GObject *object,
2072 EmpathyCallWindow *self = user_data;
2074 update_recv_codec (self, TRUE);
2078 recv_video_codecs_notify_cb (GObject *object,
2082 EmpathyCallWindow *self = user_data;
2084 update_recv_codec (self, FALSE);
2087 static const gchar *
2088 candidate_type_to_str (FsCandidate *candidate)
2090 switch (candidate->type)
2092 case FS_CANDIDATE_TYPE_HOST:
2094 case FS_CANDIDATE_TYPE_SRFLX:
2095 return "server reflexive";
2096 case FS_CANDIDATE_TYPE_PRFLX:
2097 return "peer reflexive";
2098 case FS_CANDIDATE_TYPE_RELAY:
2100 case FS_CANDIDATE_TYPE_MULTICAST:
2107 static const gchar *
2108 candidate_type_to_desc (FsCandidate *candidate)
2110 switch (candidate->type)
2112 case FS_CANDIDATE_TYPE_HOST:
2113 return _("The IP address as seen by the machine");
2114 case FS_CANDIDATE_TYPE_SRFLX:
2115 return _("The IP address as seen by a server on the Internet");
2116 case FS_CANDIDATE_TYPE_PRFLX:
2117 return _("The IP address of the peer as seen by the other side");
2118 case FS_CANDIDATE_TYPE_RELAY:
2119 return _("The IP address of a relay server");
2120 case FS_CANDIDATE_TYPE_MULTICAST:
2121 return _("The IP address of the multicast group");
2128 update_candidat_widget (EmpathyCallWindow *self,
2131 FsCandidate *candidate)
2135 g_assert (candidate != NULL);
2136 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2137 candidate->port, candidate_type_to_str (candidate));
2139 gtk_label_set_text (GTK_LABEL (label), str);
2140 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2146 candidates_changed_cb (GObject *object,
2148 EmpathyCallWindow *self)
2150 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2151 FsCandidate *candidate = NULL;
2153 if (type == FS_MEDIA_TYPE_VIDEO)
2155 /* Update remote candidate */
2156 candidate = empathy_call_handler_get_video_remote_candidate (
2159 update_candidat_widget (self, priv->video_remote_candidate_label,
2160 priv->video_remote_candidate_info_img, candidate);
2162 /* Update local candidate */
2163 candidate = empathy_call_handler_get_video_local_candidate (
2166 update_candidat_widget (self, priv->video_local_candidate_label,
2167 priv->video_local_candidate_info_img, candidate);
2171 /* Update remote candidate */
2172 candidate = empathy_call_handler_get_audio_remote_candidate (
2175 update_candidat_widget (self, priv->audio_remote_candidate_label,
2176 priv->audio_remote_candidate_info_img, candidate);
2178 /* Update local candidate */
2179 candidate = empathy_call_handler_get_audio_local_candidate (
2182 update_candidat_widget (self, priv->audio_local_candidate_label,
2183 priv->audio_local_candidate_info_img, candidate);
2188 empathy_call_window_constructed (GObject *object)
2190 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2191 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2192 TpCallChannel *call;
2195 g_assert (priv->handler != NULL);
2197 g_object_get (priv->handler, "call-channel", &call, NULL);
2198 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2199 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2200 tp_clear_object (&call);
2202 priv->contact = empathy_call_handler_get_contact (priv->handler);
2203 g_assert (priv->contact != NULL);
2204 g_object_ref (priv->contact);
2206 if (!empathy_contact_can_voip_video (priv->contact))
2208 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2209 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2212 empathy_call_window_setup_avatars (self, priv->handler);
2213 empathy_call_window_set_state_connecting (self);
2215 if (!empathy_call_handler_has_initial_video (priv->handler))
2217 gtk_toggle_tool_button_set_active (
2218 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2220 /* If call has InitialVideo, the preview will be started once the call has
2221 * been started (start_call()). */
2223 update_send_codec (self, TRUE);
2224 update_send_codec (self, FALSE);
2225 update_recv_codec (self, TRUE);
2226 update_recv_codec (self, FALSE);
2228 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2229 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2230 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2231 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2232 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2233 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2234 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2235 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2237 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2238 G_CALLBACK (candidates_changed_cb), self, 0);
2241 static void empathy_call_window_dispose (GObject *object);
2242 static void empathy_call_window_finalize (GObject *object);
2245 empathy_call_window_set_property (GObject *object,
2246 guint property_id, const GValue *value, GParamSpec *pspec)
2248 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2250 switch (property_id)
2252 case PROP_CALL_HANDLER:
2253 priv->handler = g_value_dup_object (value);
2256 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2261 empathy_call_window_get_property (GObject *object,
2262 guint property_id, GValue *value, GParamSpec *pspec)
2264 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2266 switch (property_id)
2268 case PROP_CALL_HANDLER:
2269 g_value_set_object (value, priv->handler);
2272 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2277 empathy_call_window_class_init (
2278 EmpathyCallWindowClass *empathy_call_window_class)
2280 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2281 GParamSpec *param_spec;
2283 g_type_class_add_private (empathy_call_window_class,
2284 sizeof (EmpathyCallWindowPriv));
2286 object_class->constructed = empathy_call_window_constructed;
2287 object_class->set_property = empathy_call_window_set_property;
2288 object_class->get_property = empathy_call_window_get_property;
2290 object_class->dispose = empathy_call_window_dispose;
2291 object_class->finalize = empathy_call_window_finalize;
2293 param_spec = g_param_spec_object ("handler",
2294 "handler", "The call handler",
2295 EMPATHY_TYPE_CALL_HANDLER,
2296 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2297 g_object_class_install_property (object_class,
2298 PROP_CALL_HANDLER, param_spec);
2302 empathy_call_window_dispose (GObject *object)
2304 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2305 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2307 if (priv->dispose_has_run)
2310 priv->dispose_has_run = TRUE;
2312 if (priv->handler != NULL)
2314 empathy_call_handler_stop_call (priv->handler);
2315 tp_clear_object (&priv->handler);
2318 if (priv->bus_message_source_id != 0)
2320 g_source_remove (priv->bus_message_source_id);
2321 priv->bus_message_source_id = 0;
2324 if (priv->got_video_src > 0)
2326 g_source_remove (priv->got_video_src);
2327 priv->got_video_src = 0;
2330 if (priv->inactivity_src > 0)
2332 g_source_remove (priv->inactivity_src);
2333 priv->inactivity_src = 0;
2336 tp_clear_object (&priv->pipeline);
2337 tp_clear_object (&priv->video_input);
2338 tp_clear_object (&priv->audio_input);
2339 tp_clear_object (&priv->video_tee);
2340 tp_clear_object (&priv->ui_manager);
2341 tp_clear_object (&priv->fullscreen);
2342 tp_clear_object (&priv->camera_monitor);
2343 tp_clear_object (&priv->settings);
2344 tp_clear_object (&priv->sound_mgr);
2345 tp_clear_object (&priv->mic_menu);
2346 tp_clear_object (&priv->camera_menu);
2347 tp_clear_object (&priv->transitions);
2349 g_list_free_full (priv->notifiers, g_object_unref);
2351 if (priv->timer_id != 0)
2352 g_source_remove (priv->timer_id);
2355 tp_clear_object (&priv->contact);
2357 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2361 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2363 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2365 if (priv->video_output_motion_handler_id != 0)
2367 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2368 priv->video_output_motion_handler_id);
2369 priv->video_output_motion_handler_id = 0;
2374 empathy_call_window_finalize (GObject *object)
2376 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2377 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2379 disconnect_video_output_motion_handler (self);
2381 /* free any data held directly by the object here */
2382 g_mutex_free (priv->lock);
2384 g_timer_destroy (priv->timer);
2386 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2391 empathy_call_window_new (EmpathyCallHandler *handler)
2393 return EMPATHY_CALL_WINDOW (
2394 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2398 empathy_call_window_present (EmpathyCallWindow *self,
2399 EmpathyCallHandler *handler)
2401 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2403 empathy_window_present (GTK_WINDOW (self));
2405 if (self->priv->call_state == DISCONNECTED)
2407 /* start a new call if one is not already in progress */
2408 tp_clear_object (&self->priv->handler);
2409 self->priv->handler = g_object_ref (handler);
2410 empathy_call_window_connect_handler (self);
2412 empathy_call_window_restart_call (self);
2417 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2418 GstElement *conference, gpointer user_data)
2420 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2421 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2422 FsElementAddedNotifier *notifier;
2425 DEBUG ("Conference added");
2427 /* Add notifier to set the various element properties as needed */
2428 notifier = fs_element_added_notifier_new ();
2429 keyfile = fs_utils_get_default_element_properties (conference);
2431 if (keyfile != NULL)
2432 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2434 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2436 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2438 gst_bin_add (GST_BIN (priv->pipeline), conference);
2439 gst_element_set_state (conference, GST_STATE_PLAYING);
2443 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2444 GstElement *conference, gpointer user_data)
2446 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2447 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2449 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2450 gst_element_set_state (conference, GST_STATE_NULL);
2454 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2456 GstStateChangeReturn state_change_return;
2457 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2459 if (priv->pipeline == NULL)
2462 if (priv->bus_message_source_id != 0)
2464 g_source_remove (priv->bus_message_source_id);
2465 priv->bus_message_source_id = 0;
2468 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2470 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2471 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2473 if (priv->pipeline != NULL)
2474 g_object_unref (priv->pipeline);
2475 priv->pipeline = NULL;
2477 if (priv->audio_output != NULL)
2478 g_object_unref (priv->audio_output);
2479 priv->audio_output = NULL;
2480 priv->audio_output_added = FALSE;
2482 if (priv->video_tee != NULL)
2483 g_object_unref (priv->video_tee);
2484 priv->video_tee = NULL;
2486 if (priv->video_preview != NULL)
2487 clutter_actor_destroy (priv->video_preview);
2488 priv->video_preview = NULL;
2490 /* If we destroy the preview while it's being dragged, we won't
2491 * get the ::drag-end signal, so manually destroy the clone */
2492 if (priv->drag_preview != NULL)
2494 clutter_actor_destroy (priv->drag_preview);
2495 empathy_call_window_show_preview_rectangles (self, FALSE);
2496 priv->drag_preview = NULL;
2499 priv->funnel = NULL;
2501 create_pipeline (self);
2502 /* Call will be started when user will hit the 'redial' button */
2503 priv->start_call_when_playing = FALSE;
2504 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2510 g_message ("Error: could not destroy pipeline. Closing call window");
2511 gtk_widget_destroy (GTK_WIDGET (self));
2518 reset_details_pane (EmpathyCallWindow *self)
2520 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2522 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2523 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2524 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2525 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2529 empathy_call_window_disconnected (EmpathyCallWindow *self,
2532 gboolean could_disconnect = FALSE;
2533 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2534 gboolean could_reset_pipeline;
2536 /* Leave full screen mode if needed */
2537 gtk_window_unfullscreen (GTK_WINDOW (self));
2539 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2540 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2542 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2544 if (priv->call_state == CONNECTING)
2545 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2547 if (priv->call_state != REDIALING)
2548 priv->call_state = DISCONNECTED;
2550 /* Show the toolbar */
2551 clutter_state_set_state (priv->transitions, "fade-in");
2553 if (could_reset_pipeline)
2555 g_mutex_lock (priv->lock);
2557 g_timer_stop (priv->timer);
2559 if (priv->timer_id != 0)
2560 g_source_remove (priv->timer_id);
2563 g_mutex_unlock (priv->lock);
2566 /* We are about to destroy the window, no need to update it or create
2567 * a video preview */
2570 empathy_call_window_status_message (self, _("Disconnected"));
2572 empathy_call_window_show_hangup_button (self, FALSE);
2574 /* Unsensitive the camera and mic button */
2575 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2576 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2578 /* Be sure that the mic button is enabled */
2579 gtk_toggle_tool_button_set_active (
2580 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2582 if (priv->camera_state == CAMERA_STATE_ON)
2584 /* Restart the preview with the new pipeline. */
2585 display_video_preview (self, TRUE);
2588 /* destroy the video output; it will be recreated when we'll redial */
2589 disconnect_video_output_motion_handler (self);
2590 if (priv->video_output != NULL)
2591 clutter_actor_destroy (priv->video_output);
2592 priv->video_output = NULL;
2593 if (priv->got_video_src > 0)
2595 g_source_remove (priv->got_video_src);
2596 priv->got_video_src = 0;
2599 gtk_widget_show (priv->remote_user_avatar_widget);
2601 reset_details_pane (self);
2603 priv->sending_video = FALSE;
2604 priv->call_started = FALSE;
2606 could_disconnect = TRUE;
2608 /* TODO: display the self avatar of the preview (depends if the "Always
2609 * Show Video Preview" is enabled or not) */
2612 return could_disconnect;
2617 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2620 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2621 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2623 if (empathy_call_window_disconnected (self, TRUE) &&
2624 priv->call_state == REDIALING)
2625 empathy_call_window_restart_call (self);
2629 empathy_call_window_content_is_raw (TfContent *content)
2631 FsConference *conference;
2634 g_object_get (content, "fs-conference", &conference, NULL);
2635 g_assert (conference != NULL);
2637 /* FIXME: Ugly hack, update when moving a packetization property into
2639 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2640 gst_object_unref (conference);
2646 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2648 EmpathyCallWindow *self)
2650 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2651 FsMediaType media_type;
2653 DEBUG ("removing content");
2655 g_object_get (content, "media-type", &media_type, NULL);
2658 * This assumes that there is only one video stream per channel...
2661 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2663 if (priv->funnel != NULL)
2667 output = priv->video_output_sink;
2669 gst_element_set_state (output, GST_STATE_NULL);
2670 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2672 gst_bin_remove (GST_BIN (priv->pipeline), output);
2673 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2674 priv->funnel = NULL;
2677 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2679 if (priv->audio_output != NULL)
2681 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2683 if (priv->audio_output_added)
2684 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2685 priv->audio_output = NULL;
2686 priv->audio_output_added = FALSE;
2691 g_assert_not_reached ();
2698 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2700 EmpathyCallWindow *self)
2702 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2704 DEBUG ("Framerate changed to %u", framerate);
2706 if (priv->video_input != NULL)
2707 empathy_video_src_set_framerate (priv->video_input, framerate);
2711 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2714 EmpathyCallWindow *self)
2716 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2718 DEBUG ("Resolution changed to %ux%u", width, height);
2720 if (priv->video_input != NULL)
2722 empathy_video_src_set_resolution (priv->video_input, width, height);
2726 /* Called with global lock held */
2728 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2730 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2734 if (priv->funnel == NULL)
2736 output = priv->video_output_sink;
2738 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2742 g_warning ("Could not create fsfunnel");
2746 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2748 gst_object_unref (priv->funnel);
2749 priv->funnel = NULL;
2750 g_warning ("Could not add funnel to pipeline");
2754 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2756 g_warning ("Could not add the video output widget to the pipeline");
2760 if (!gst_element_link (priv->funnel, output))
2762 g_warning ("Could not link output sink to funnel");
2763 goto error_output_added;
2766 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2768 g_warning ("Could not start video sink");
2769 goto error_output_added;
2772 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2774 g_warning ("Could not start funnel");
2775 goto error_output_added;
2779 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2782 g_warning ("Could not get request pad from funnel");
2789 gst_element_set_locked_state (priv->funnel, TRUE);
2790 gst_element_set_locked_state (output, TRUE);
2792 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2793 gst_element_set_state (output, GST_STATE_NULL);
2795 gst_bin_remove (GST_BIN (priv->pipeline), output);
2796 gst_element_set_locked_state (output, FALSE);
2800 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2801 priv->funnel = NULL;
2806 /* Called with global lock held */
2808 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2811 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2813 GstPadTemplate *template;
2815 if (!priv->audio_output_added)
2817 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2819 g_warning ("Could not add audio sink to pipeline");
2820 g_object_unref (priv->audio_output);
2821 goto error_add_output;
2824 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2826 g_warning ("Could not start audio sink");
2831 template = gst_element_class_get_pad_template (
2832 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2834 pad = gst_element_request_pad (priv->audio_output,
2835 template, NULL, NULL);
2839 g_warning ("Could not get sink pad from sink");
2846 gst_element_set_locked_state (priv->audio_output, TRUE);
2847 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2848 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2849 priv->audio_output = NULL;
2857 empathy_call_window_update_timer (gpointer user_data)
2859 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2860 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2861 const gchar *status;
2865 time_ = g_timer_elapsed (priv->timer, NULL);
2867 if (priv->call_state == HELD)
2868 status = _("On hold");
2869 else if (!gtk_toggle_tool_button_get_active (
2870 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2873 status = _("Duration");
2875 /* Translators: 'status - minutes:seconds' the caller has been connected */
2876 str = g_strdup_printf (_("%s — %d:%02dm"),
2878 (int) time_ / 60, (int) time_ % 60);
2879 empathy_call_window_status_message (self, str);
2887 EMP_RESPONSE_BALANCE
2891 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2895 switch (response_id)
2897 case GTK_RESPONSE_CLOSE:
2898 gtk_widget_destroy (GTK_WIDGET (info_bar));
2900 case EMP_RESPONSE_BALANCE:
2901 empathy_url_show (GTK_WIDGET (info_bar),
2902 g_object_get_data (G_OBJECT (info_bar), "uri"));
2908 display_error (EmpathyCallWindow *self,
2912 const gchar *details,
2913 const gchar *button_text,
2915 gint button_response)
2917 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2918 GtkWidget *info_bar;
2919 GtkWidget *content_area;
2926 /* Create info bar */
2927 info_bar = gtk_info_bar_new ();
2929 if (button_text != NULL)
2931 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2932 button_text, button_response);
2933 g_object_set_data_full (G_OBJECT (info_bar),
2934 "uri", g_strdup (uri), g_free);
2937 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2938 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
2940 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2942 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2944 /* hbox containing the image and the messages vbox */
2945 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2946 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2949 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2950 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2952 /* vbox containing the main message and the details expander */
2953 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2954 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2957 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2959 label = gtk_label_new (NULL);
2960 gtk_label_set_markup (GTK_LABEL (label), txt);
2961 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2962 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2965 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2968 if (details != NULL)
2970 GtkWidget *expander;
2972 expander = gtk_expander_new (_("Technical Details"));
2974 txt = g_strdup_printf ("<i>%s</i>", details);
2976 label = gtk_label_new (NULL);
2977 gtk_label_set_markup (GTK_LABEL (label), txt);
2978 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2979 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2982 gtk_container_add (GTK_CONTAINER (expander), label);
2983 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2986 g_signal_connect (info_bar, "response",
2987 G_CALLBACK (on_error_infobar_response_cb), NULL);
2989 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2990 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2991 gtk_widget_show_all (info_bar);
2996 media_stream_error_to_txt (EmpathyCallWindow *self,
2997 TpCallChannel *call,
2999 TpMediaStreamError error)
3001 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3002 const gchar *cm = NULL;
3008 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3010 return g_strdup_printf (
3011 _("%s's software does not understand any of the audio formats "
3012 "supported by your computer"),
3013 empathy_contact_get_alias (priv->contact));
3015 return g_strdup_printf (
3016 _("%s's software does not understand any of the video formats "
3017 "supported by your computer"),
3018 empathy_contact_get_alias (priv->contact));
3020 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3021 return g_strdup_printf (
3022 _("Can't establish a connection to %s. "
3023 "One of you might be on a network that does not allow "
3024 "direct connections."),
3025 empathy_contact_get_alias (priv->contact));
3027 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3028 return g_strdup (_("There was a failure on the network"));
3030 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3032 return g_strdup (_("The audio formats necessary for this call "
3033 "are not installed on your computer"));
3035 return g_strdup (_("The video formats necessary for this call "
3036 "are not installed on your computer"));
3038 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3039 tp_connection_parse_object_path (
3040 tp_channel_borrow_connection (TP_CHANNEL (call)),
3043 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3044 "product=Telepathy&component=%s", cm);
3046 result = g_strdup_printf (
3047 _("Something unexpected happened in a Telepathy component. "
3048 "Please <a href=\"%s\">report this bug</a> and attach "
3049 "logs gathered from the 'Debug' window in the Help menu."), url);
3055 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3056 return g_strdup (_("There was a failure in the call engine"));
3058 case TP_MEDIA_STREAM_ERROR_EOS:
3059 return g_strdup (_("The end of the stream was reached"));
3061 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3068 empathy_call_window_stream_error (EmpathyCallWindow *self,
3069 TpCallChannel *call,
3078 desc = media_stream_error_to_txt (self, call, audio, code);
3081 /* No description, use the error message. That's not great as it's not
3082 * localized but it's better than nothing. */
3083 display_error (self, call, icon, title, msg, NULL);
3087 display_error (self, call, icon, title, desc, msg);
3093 empathy_call_window_audio_stream_error (TpCallChannel *call,
3096 EmpathyCallWindow *self)
3098 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3099 "gnome-stock-mic", _("Can't establish audio stream"));
3103 empathy_call_window_video_stream_error (TpCallChannel *call,
3106 EmpathyCallWindow *self)
3108 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3109 "camera-web", _("Can't establish video stream"));
3114 show_balance_error (EmpathyCallWindow *self)
3118 gchar *balance, *tmp;
3119 const gchar *uri, *currency;
3123 g_object_get (self->priv->handler,
3124 "call-channel", &call,
3127 conn = tp_channel_borrow_connection (call);
3128 g_object_unref (call);
3130 uri = tp_connection_get_balance_uri (conn);
3132 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3134 /* unknown balance */
3135 balance = g_strdup ("(--)");
3139 char *money = empathy_format_currency (amount, scale, currency);
3141 balance = g_strdup_printf ("%s %s",
3146 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3148 display_error (self,
3150 _("Sorry, you don’t have enough credit for that call."),
3154 EMP_RESPONSE_BALANCE);
3161 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3164 EmpathyCallWindow *self)
3166 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3167 TpCallChannel *call;
3168 gboolean can_send_video;
3170 if (state == TP_CALL_STATE_ENDED)
3172 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3173 empathy_call_window_disconnected (self, TRUE);
3174 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3175 show_balance_error (self);
3179 if (state != TP_CALL_STATE_ACCEPTED)
3182 if (priv->call_state == CONNECTED)
3185 g_timer_start (priv->timer);
3186 priv->call_state = CONNECTED;
3188 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3190 can_send_video = priv->video_input != NULL &&
3191 empathy_contact_can_voip_video (priv->contact) &&
3192 empathy_camera_monitor_get_available (priv->camera_monitor);
3194 g_object_get (priv->handler, "call-channel", &call, NULL);
3196 if (tp_call_channel_has_dtmf (call))
3197 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3199 if (priv->video_input == NULL)
3200 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3202 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3204 empathy_call_window_show_hangup_button (self, TRUE);
3206 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3208 clutter_actor_hide (priv->video_output);
3209 gtk_widget_show (priv->remote_user_avatar_widget);
3211 g_object_unref (call);
3213 g_mutex_lock (priv->lock);
3215 priv->timer_id = g_timeout_add_seconds (1,
3216 empathy_call_window_update_timer, self);
3218 g_mutex_unlock (priv->lock);
3220 empathy_call_window_update_timer (self);
3222 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3226 empathy_call_window_show_video_output_cb (gpointer user_data)
3228 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3230 if (self->priv->video_output != NULL)
3232 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3233 clutter_actor_show (self->priv->video_output);
3234 clutter_actor_raise_top (self->priv->overlay_box);
3241 empathy_call_window_check_video_cb (gpointer data)
3243 EmpathyCallWindow *self = data;
3245 if (self->priv->got_video)
3247 self->priv->got_video = FALSE;
3251 /* No video in the last N seconds, display the remote avatar */
3252 empathy_call_window_show_video_output (self, FALSE);
3257 /* Called from the streaming thread */
3259 empathy_call_window_video_probe_cb (GstPad *pad,
3260 GstMiniObject *mini_obj,
3261 EmpathyCallWindow *self)
3264 if (GST_IS_EVENT (mini_obj))
3267 if (G_UNLIKELY (!self->priv->got_video))
3269 /* show the remote video */
3270 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3271 empathy_call_window_show_video_output_cb,
3272 g_object_ref (self), g_object_unref);
3274 self->priv->got_video = TRUE;
3280 /* Called from the streaming thread */
3282 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3283 TfContent *content, GstPad *src, gpointer user_data)
3285 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3286 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3287 gboolean retval = FALSE;
3292 g_mutex_lock (priv->lock);
3294 g_object_get (content, "media-type", &media_type, NULL);
3298 case TP_MEDIA_STREAM_TYPE_AUDIO:
3299 pad = empathy_call_window_get_audio_sink_pad (self, content);
3301 case TP_MEDIA_STREAM_TYPE_VIDEO:
3302 g_idle_add (empathy_call_window_show_video_output_cb, self);
3303 pad = empathy_call_window_get_video_sink_pad (self);
3305 gst_pad_add_data_probe (src,
3306 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3307 if (priv->got_video_src > 0)
3308 g_source_remove (priv->got_video_src);
3309 priv->got_video_src = g_timeout_add_seconds (1,
3310 empathy_call_window_check_video_cb, self);
3313 g_assert_not_reached ();
3319 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3320 g_warning ("Could not link %s sink pad",
3321 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3325 gst_object_unref (pad);
3329 /* If no sink could be linked, try to add fakesink to prevent the whole call
3334 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3336 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3338 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3339 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3340 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3342 gst_element_set_locked_state (fakesink, TRUE);
3343 gst_element_set_state (fakesink, GST_STATE_NULL);
3344 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3348 DEBUG ("Could not link real sink, linked fakesink instead");
3350 gst_object_unref (sinkpad);
3354 gst_object_unref (fakesink);
3359 g_mutex_unlock (priv->lock);
3365 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3368 EmpathyCallWindowPriv *priv = self->priv;
3370 g_assert (priv->audio_output_added == FALSE);
3371 g_assert (priv->audio_output == FALSE);
3373 priv->audio_output = empathy_audio_sink_new ();
3374 g_object_ref_sink (priv->audio_output);
3376 /* volume button to output volume linking */
3377 g_object_bind_property (priv->audio_output, "volume",
3378 priv->volume_button, "value",
3379 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3381 g_object_bind_property_full (content, "requested-output-volume",
3382 priv->audio_output, "volume",
3384 audio_control_volume_to_element,
3385 element_volume_to_audio_control,
3388 /* Link volumes together, sync the current audio input volume property
3389 * back to farstream first */
3390 g_object_bind_property_full (priv->audio_output, "volume",
3391 content, "reported-output-volume",
3392 G_BINDING_SYNC_CREATE,
3393 element_volume_to_audio_control,
3394 audio_control_volume_to_element,
3397 /* For raw audio conferences assume that the producer of the raw data
3398 * has already processed it, so turn off any echo cancellation and any
3399 * other audio improvements that come with it */
3400 empathy_audio_sink_set_echo_cancel (
3401 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3402 !empathy_call_window_content_is_raw (content));
3407 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3408 TfContent *content, gpointer user_data)
3410 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3411 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3413 FsMediaType media_type;
3414 gboolean retval = FALSE;
3416 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3417 g_assert (sink != NULL);
3421 case FS_MEDIA_TYPE_AUDIO:
3423 /* For raw audio conferences assume that the receiver of the raw data
3424 * wants it unprocessed, so turn off any echo cancellation and any
3425 * other audio improvements that come with it */
3426 empathy_audio_src_set_echo_cancel (
3427 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3428 !empathy_call_window_content_is_raw (content));
3430 /* Link volumes together, sync the current audio input volume property
3431 * back to farstream first */
3432 g_object_bind_property_full (content, "requested-input-volume",
3433 priv->audio_input, "volume",
3435 audio_control_volume_to_element,
3436 element_volume_to_audio_control,
3439 g_object_bind_property_full (priv->audio_input, "volume",
3440 content, "reported-input-volume",
3441 G_BINDING_SYNC_CREATE,
3442 element_volume_to_audio_control,
3443 audio_control_volume_to_element,
3446 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3448 g_warning ("Could not add audio source to pipeline");
3452 pad = gst_element_get_static_pad (priv->audio_input, "src");
3455 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3456 g_warning ("Could not get source pad from audio source");
3460 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3462 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3463 gst_object_unref (pad);
3464 g_warning ("Could not link audio source to farsight");
3467 gst_object_unref (pad);
3469 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3471 g_warning ("Could not start audio source");
3472 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3473 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3477 /* Prepare our audio output, not added yet though */
3478 empathy_call_window_prepare_audio_output (self, content);
3482 case FS_MEDIA_TYPE_VIDEO:
3483 if (priv->video_tee != NULL)
3485 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3486 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3488 g_warning ("Could not link video source input pipeline");
3491 gst_object_unref (pad);
3497 g_assert_not_reached ();
3500 gst_object_unref (sink);
3505 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3507 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3508 GstElement *preview;
3510 disable_camera (self);
3512 DEBUG ("remove video input");
3513 preview = priv->video_preview_sink;
3515 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3516 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3517 gst_element_set_state (preview, GST_STATE_NULL);
3519 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3522 g_object_unref (priv->video_input);
3523 priv->video_input = NULL;
3524 g_object_unref (priv->video_tee);
3525 priv->video_tee = NULL;
3526 clutter_actor_destroy (priv->video_preview);
3527 priv->video_preview = NULL;
3529 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3533 start_call (EmpathyCallWindow *self)
3535 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3537 priv->call_started = TRUE;
3538 empathy_call_handler_start_call (priv->handler,
3539 gtk_get_current_event_time ());
3541 if (empathy_call_handler_has_initial_video (priv->handler))
3543 TpCallChannel *call;
3546 g_object_get (priv->handler, "call-channel", &call, NULL);
3547 /* If the call channel isn't set yet we're requesting it, if we're
3548 * requesting it with initial video it should be PENDING_SEND when we get
3551 s = TP_SENDING_STATE_PENDING_SEND;
3553 s = empathy_call_channel_get_video_state (call);
3555 if (s == TP_SENDING_STATE_PENDING_SEND ||
3556 s == TP_SENDING_STATE_SENDING)
3558 /* Enable 'send video' buttons and display the preview */
3559 gtk_toggle_tool_button_set_active (
3560 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3564 gtk_toggle_tool_button_set_active (
3565 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3567 if (priv->video_preview == NULL)
3569 create_video_preview (self);
3570 add_video_preview_to_pipeline (self);
3575 g_object_unref (call);
3580 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3583 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3584 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3585 GstState newstate, pending;
3587 empathy_call_handler_bus_message (priv->handler, bus, message);
3589 switch (GST_MESSAGE_TYPE (message))
3591 case GST_MESSAGE_STATE_CHANGED:
3592 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3594 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3596 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3597 !priv->call_started)
3599 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3600 if (newstate == GST_STATE_PAUSED)
3602 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3603 priv->pipeline_playing = TRUE;
3605 if (priv->start_call_when_playing)
3609 if (priv->video_preview_sink != NULL &&
3610 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3612 gst_message_parse_state_changed (message, NULL, &newstate,
3615 if (newstate == GST_STATE_PLAYING &&
3616 pending == GST_STATE_VOID_PENDING)
3617 empathy_call_window_stop_camera_spinning (self);
3620 case GST_MESSAGE_ERROR:
3622 GError *error = NULL;
3623 GstElement *gst_error;
3627 gst_message_parse_error (message, &error, &debug);
3628 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3630 g_message ("Element error: %s -- %s\n", error->message, debug);
3632 name = gst_element_get_name (gst_error);
3633 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3635 /* Remove the video input and continue */
3636 if (priv->video_input != NULL)
3637 empathy_call_window_remove_video_input (self);
3638 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3642 empathy_call_window_disconnected (self, TRUE);
3645 g_error_free (error);
3648 case GST_MESSAGE_UNKNOWN:
3649 case GST_MESSAGE_EOS:
3650 case GST_MESSAGE_WARNING:
3651 case GST_MESSAGE_INFO:
3652 case GST_MESSAGE_TAG:
3653 case GST_MESSAGE_BUFFERING:
3654 case GST_MESSAGE_STATE_DIRTY:
3655 case GST_MESSAGE_STEP_DONE:
3656 case GST_MESSAGE_CLOCK_PROVIDE:
3657 case GST_MESSAGE_CLOCK_LOST:
3658 case GST_MESSAGE_NEW_CLOCK:
3659 case GST_MESSAGE_STRUCTURE_CHANGE:
3660 case GST_MESSAGE_STREAM_STATUS:
3661 case GST_MESSAGE_APPLICATION:
3662 case GST_MESSAGE_ELEMENT:
3663 case GST_MESSAGE_SEGMENT_START:
3664 case GST_MESSAGE_SEGMENT_DONE:
3665 case GST_MESSAGE_DURATION:
3666 case GST_MESSAGE_ANY:
3675 empathy_call_window_members_changed_cb (TpCallChannel *call,
3676 GHashTable *updates,
3678 TpCallStateReason *reason,
3679 EmpathyCallWindow *self)
3681 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3682 GHashTableIter iter;
3683 gpointer key, value;
3684 gboolean held = FALSE;
3686 g_hash_table_iter_init (&iter, updates);
3687 while (g_hash_table_iter_next (&iter, &key, &value))
3689 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3691 /* This assumes this is a 1-1 call, otherwise one participant
3692 * putting the call on hold wouldn't mean the call is on hold
3700 priv->call_state = HELD;
3701 else if (priv->call_state == HELD)
3702 priv->call_state = CONNECTED;
3706 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3708 EmpathyCallWindow *self)
3710 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3711 TpCallChannel *call;
3713 g_object_get (priv->handler, "call-channel", &call, NULL);
3718 tp_g_signal_connect_object (call, "audio-stream-error",
3719 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3720 tp_g_signal_connect_object (call, "video-stream-error",
3721 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3724 tp_g_signal_connect_object (call, "members-changed",
3725 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3727 g_object_unref (call);
3731 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3733 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3734 TpCallChannel *call;
3736 g_signal_connect (priv->handler, "state-changed",
3737 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3738 g_signal_connect (priv->handler, "conference-added",
3739 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3740 g_signal_connect (priv->handler, "conference-removed",
3741 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3742 g_signal_connect (priv->handler, "closed",
3743 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3744 g_signal_connect (priv->handler, "src-pad-added",
3745 G_CALLBACK (empathy_call_window_src_added_cb), self);
3746 g_signal_connect (priv->handler, "content-added",
3747 G_CALLBACK (empathy_call_window_content_added_cb), self);
3748 g_signal_connect (priv->handler, "content-removed",
3749 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3751 /* We connect to ::call-channel unconditionally since we'll
3752 * get new channels if we hangup and redial or if we reuse the
3754 g_signal_connect (priv->handler, "notify::call-channel",
3755 G_CALLBACK (call_handler_notify_call_cb), self);
3757 g_signal_connect (priv->handler, "framerate-changed",
3758 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3759 g_signal_connect (priv->handler, "resolution-changed",
3760 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3762 g_object_get (priv->handler, "call-channel", &call, NULL);
3765 /* We won't get notify::call-channel for this channel, so
3766 * directly call the callback. */
3767 call_handler_notify_call_cb (priv->handler, NULL, self);
3768 g_object_unref (call);
3773 empathy_call_window_realized_cb (GtkWidget *widget,
3774 EmpathyCallWindow *self)
3778 /* Make the hangup button twice as wide */
3779 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3780 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3782 empathy_call_window_connect_handler (self);
3784 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3788 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3789 EmpathyCallWindow *window)
3791 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3793 if (priv->pipeline != NULL)
3795 if (priv->bus_message_source_id != 0)
3797 g_source_remove (priv->bus_message_source_id);
3798 priv->bus_message_source_id = 0;
3801 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3804 if (priv->call_state == CONNECTING)
3805 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3811 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3814 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3816 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3821 gtk_widget_hide (priv->dtmf_panel);
3822 gtk_widget_hide (menu);
3823 gtk_widget_hide (priv->toolbar);
3827 if (priv->dialpad_was_visible_before_fs)
3828 gtk_widget_show (priv->dtmf_panel);
3830 gtk_widget_show (menu);
3831 gtk_widget_show (priv->toolbar);
3833 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3834 priv->original_height_before_fs);
3839 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3841 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3843 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3844 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3845 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3846 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3848 if (priv->video_output != NULL)
3851 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3852 priv->video_output, TRUE, TRUE,
3853 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3860 empathy_call_window_state_event_cb (GtkWidget *widget,
3861 GdkEventWindowState *event, EmpathyCallWindow *window)
3863 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3865 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3866 gboolean set_fullscreen = event->new_window_state &
3867 GDK_WINDOW_STATE_FULLSCREEN;
3871 gboolean dialpad_was_visible;
3872 GtkAllocation allocation;
3873 gint original_width, original_height;
3875 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3876 original_width = allocation.width;
3877 original_height = allocation.height;
3879 g_object_get (priv->dtmf_panel,
3880 "visible", &dialpad_was_visible,
3883 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3884 priv->original_width_before_fs = original_width;
3885 priv->original_height_before_fs = original_height;
3887 if (priv->video_output_motion_handler_id == 0 &&
3888 priv->video_output != NULL)
3890 priv->video_output_motion_handler_id = g_signal_connect (
3891 G_OBJECT (priv->video_container), "motion-notify-event",
3892 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3898 disconnect_video_output_motion_handler (window);
3901 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3903 show_controls (window, set_fullscreen);
3904 show_borders (window, set_fullscreen);
3905 gtk_action_set_stock_id (priv->menu_fullscreen,
3906 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3907 priv->is_fullscreen = set_fullscreen;
3914 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3917 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3918 int w, h, dialpad_width;
3919 GtkAllocation allocation;
3921 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3922 w = allocation.width;
3923 h = allocation.height;
3925 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3929 gtk_widget_show (priv->dtmf_panel);
3935 gtk_widget_hide (priv->dtmf_panel);
3939 gtk_window_resize (GTK_WINDOW (window), w, h);
3943 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3946 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3947 TpCallChannel *call;
3949 priv->sending_video = (state == CAMERA_STATE_ON);
3951 if (state == CAMERA_STATE_ON)
3953 /* When we start sending video, we want to show the video preview by
3955 display_video_preview (window, TRUE);
3959 display_video_preview (window, FALSE);
3962 if (priv->call_state != CONNECTED)
3965 g_object_get (priv->handler, "call-channel", &call, NULL);
3966 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3967 empathy_call_channel_send_video (call, priv->sending_video);
3968 g_object_unref (call);
3972 empathy_call_window_hangup_cb (gpointer object,
3973 EmpathyCallWindow *self)
3975 /* stopping the call will put it the ENDED state and
3976 * from state_changed_cb we'll reconfigure the window
3978 empathy_call_handler_stop_call (self->priv->handler);
3982 empathy_call_window_restart_call (EmpathyCallWindow *window)
3984 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3986 /* Remove error info bars */
3987 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3988 (GtkCallback) gtk_widget_destroy, NULL);
3990 create_video_output_widget (window);
3991 priv->outgoing = TRUE;
3992 empathy_call_window_set_state_connecting (window);
3994 if (priv->pipeline_playing)
3995 start_call (window);
3997 /* call will be started when the pipeline is ready */
3998 priv->start_call_when_playing = TRUE;
4000 empathy_call_window_setup_avatars (window, priv->handler);
4002 empathy_call_window_show_hangup_button (window, TRUE);
4006 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4007 EmpathyCallWindow *window)
4011 active = gtk_toggle_tool_button_get_active (button);
4013 empathy_call_window_show_dialpad (window, active);
4017 empathy_call_window_fullscreen_cb (gpointer object,
4018 EmpathyCallWindow *window)
4020 empathy_call_window_fullscreen_toggle (window);
4024 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4026 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4028 if (priv->is_fullscreen)
4029 gtk_window_unfullscreen (GTK_WINDOW (window));
4031 gtk_window_fullscreen (GTK_WINDOW (window));
4035 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4036 GdkEventButton *event, EmpathyCallWindow *window)
4038 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4040 empathy_call_window_video_menu_popup (window, event->button);
4048 empathy_call_window_key_press_cb (GtkWidget *video_output,
4049 GdkEventKey *event, EmpathyCallWindow *window)
4051 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4053 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4055 /* Since we are in fullscreen mode, toggling will bring us back to
4057 empathy_call_window_fullscreen_toggle (window);
4065 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4066 GdkEventMotion *event, EmpathyCallWindow *window)
4068 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4070 if (priv->is_fullscreen)
4072 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4074 /* Show the bottom toolbar */
4075 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4082 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4086 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4088 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4090 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4091 button, gtk_get_current_event_time ());
4092 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4096 empathy_call_window_status_message (EmpathyCallWindow *self,
4099 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4103 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4105 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4107 return priv->ui_manager;
4110 EmpathyGstAudioSrc *
4111 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4113 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4115 return (EmpathyGstAudioSrc *) priv->audio_input;
4118 EmpathyGstVideoSrc *
4119 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4121 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4125 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4126 const gchar *device)
4128 EmpathyGstVideoSrc *video;
4131 /* Restart the camera only if it's already running */
4132 running = (self->priv->video_preview != NULL);
4133 video = empathy_call_window_get_video_src (self);
4136 empathy_call_window_play_camera (self, FALSE);
4138 empathy_video_src_change_device (video, device);
4141 empathy_call_window_play_camera (self, TRUE);