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-request-util.h>
47 #include <libempathy/empathy-utils.h>
49 #include <libempathy-gtk/empathy-avatar-image.h>
50 #include <libempathy-gtk/empathy-dialpad-widget.h>
51 #include <libempathy-gtk/empathy-ui-utils.h>
52 #include <libempathy-gtk/empathy-sound-manager.h>
53 #include <libempathy-gtk/empathy-geometry.h>
54 #include <libempathy-gtk/empathy-images.h>
55 #include <libempathy-gtk/empathy-call-utils.h>
57 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
58 #include <libempathy/empathy-debug.h>
60 #include "empathy-call-window.h"
61 #include "empathy-call-window-fullscreen.h"
62 #include "empathy-call-factory.h"
63 #include "empathy-about-dialog.h"
64 #include "empathy-audio-src.h"
65 #include "empathy-audio-sink.h"
66 #include "empathy-video-src.h"
67 #include "empathy-mic-menu.h"
68 #include "empathy-preferences.h"
69 #include "empathy-rounded-actor.h"
70 #include "empathy-rounded-rectangle.h"
71 #include "empathy-rounded-texture.h"
72 #include "empathy-camera-menu.h"
74 #define CONTENT_HBOX_SPACING 3
75 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
76 #define OVERLAY_MARGIN 6
78 #define REMOTE_VIDEO_DEFAULT_WIDTH 320
79 #define REMOTE_VIDEO_DEFAULT_HEIGHT 240
81 #define SELF_VIDEO_SECTION_WIDTH 120
82 #define SELF_VIDEO_SECTION_HEIGHT 90
83 #define SELF_VIDEO_SECTION_MARGIN 2
84 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
86 /* The avatar's default width and height are set to the same value because we
87 want a square icon. */
88 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
89 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
91 #define SMALL_TOOLBAR_SIZE 36
93 /* If an video input error occurs, the error message will start with "v4l" */
94 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
96 /* The time interval in milliseconds between 2 outgoing rings */
97 #define MS_BETWEEN_RING 500
99 /* The roundedness of preview box and placeholders */
100 #define PREVIEW_ROUND_FACTOR 16
102 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
105 PROP_CALL_HANDLER = 1,
109 RINGING, /* Incoming call */
110 CONNECTING, /* Outgoing call */
111 CONNECTED, /* Connected */
112 HELD, /* Connected, but on hold */
113 DISCONNECTED, /* Disconnected */
114 REDIALING /* Redialing (special case of CONNECTING) */
118 CAMERA_STATE_OFF = 0,
124 PREVIEW_POS_TOP_LEFT,
125 PREVIEW_POS_TOP_RIGHT,
126 PREVIEW_POS_BOTTOM_LEFT,
127 PREVIEW_POS_BOTTOM_RIGHT,
130 struct _EmpathyCallWindowPriv
132 gboolean dispose_has_run;
133 EmpathyCallHandler *handler;
135 EmpathyContact *contact;
137 EmpathyCameraMonitor *camera_monitor;
142 GtkUIManager *ui_manager;
143 GtkWidget *errors_vbox;
144 /* widget displays the video received from the remote user. This widget is
145 * alive only during call. */
146 ClutterActor *video_output;
147 ClutterActor *video_preview;
148 ClutterActor *drag_preview;
149 ClutterActor *preview_shown_button;
150 ClutterActor *preview_hidden_button;
151 ClutterActor *preview_rectangle1;
152 ClutterActor *preview_rectangle2;
153 ClutterActor *preview_rectangle3;
154 ClutterActor *preview_rectangle4;
155 ClutterActor *preview_spinner_actor;
156 GtkWidget *preview_spinner_widget;
157 GtkWidget *video_container;
158 GtkWidget *remote_user_avatar_widget;
159 GtkWidget *remote_user_avatar_toolbar;
160 GtkWidget *remote_user_name_toolbar;
161 GtkWidget *remote_user_status_toolbar;
162 GtkWidget *status_label;
163 GtkWidget *hangup_button;
164 GtkWidget *audio_call_button;
165 GtkWidget *video_call_button;
166 GtkWidget *mic_button;
167 GtkWidget *microphone_icon;
168 GtkWidget *volume_button;
169 GtkWidget *camera_button;
170 GtkWidget *dialpad_button;
172 GtkWidget *bottom_toolbar;
173 ClutterActor *floating_toolbar;
175 GtkAction *menu_fullscreen;
176 GtkAction *menu_swap_camera;
178 ClutterState *transitions;
180 /* The main box covering all the stage, contaning remote avatar/video */
181 ClutterActor *video_box;
182 ClutterLayoutManager *video_layout;
184 /* A bin layout manager containing a bin for previews
185 * and the floating toolbar */
186 ClutterActor *overlay_bin;
187 ClutterLayoutManager *overlay_layout;
189 /* Bin layout for the previews */
190 ClutterActor *preview_box;
191 ClutterLayoutManager *preview_layout;
193 /* Coordinates of the preview drag event's start. */
194 PreviewPosition preview_pos;
196 /* We keep a reference on the hbox which contains the main content so we can
197 easilly repack everything when toggling fullscreen */
198 GtkWidget *content_hbox;
200 /* These are used to accept or reject an incoming call when the status
202 GtkWidget *incoming_call_dialog;
203 TpCallChannel *pending_channel;
204 TpChannelDispatchOperation *pending_cdo;
205 TpAddDispatchOperationContext *pending_context;
207 gulong video_output_motion_handler_id;
208 guint bus_message_source_id;
210 GtkWidget *dtmf_panel;
213 GtkWidget *details_vbox;
214 GtkWidget *vcodec_encoding_label;
215 GtkWidget *acodec_encoding_label;
216 GtkWidget *vcodec_decoding_label;
217 GtkWidget *acodec_decoding_label;
219 GtkWidget *audio_remote_candidate_label;
220 GtkWidget *audio_local_candidate_label;
221 GtkWidget *video_remote_candidate_label;
222 GtkWidget *video_local_candidate_label;
223 GtkWidget *video_remote_candidate_info_img;
224 GtkWidget *video_local_candidate_info_img;
225 GtkWidget *audio_remote_candidate_info_img;
226 GtkWidget *audio_local_candidate_info_img;
228 GstElement *video_input;
229 GstElement *video_preview_sink;
230 GstElement *video_output_sink;
231 GstElement *audio_input;
232 GstElement *audio_output;
233 gboolean audio_output_added;
234 GstElement *pipeline;
235 GstElement *video_tee;
245 gboolean call_started;
246 gboolean sending_video;
247 CameraState camera_state;
249 EmpathyCallWindowFullscreen *fullscreen;
250 gboolean is_fullscreen;
255 guint inactivity_src;
257 /* Those fields represent the state of the window before it actually was in
259 gboolean dialpad_was_visible_before_fs;
260 gint original_width_before_fs;
261 gint original_height_before_fs;
263 gint x, y, w, h, dialpad_width;
266 /* TRUE if the call should be started when the pipeline is playing */
267 gboolean start_call_when_playing;
268 /* TRUE if we requested to set the pipeline in the playing state */
269 gboolean pipeline_playing;
271 EmpathySoundManager *sound_mgr;
274 EmpathyMicMenu *mic_menu;
275 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);
327 static gboolean empathy_call_window_update_timer (gpointer user_data);
330 make_background_transparent (GtkClutterActor *actor)
332 GdkRGBA transparent = { 0., 0., 0., 0. };
335 widget = gtk_clutter_actor_get_widget (actor);
336 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
340 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
343 gtk_widget_set_visible (self->priv->hangup_button, show);
344 gtk_widget_set_visible (self->priv->audio_call_button, !show);
345 gtk_widget_set_visible (self->priv->video_call_button, !show);
349 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
350 EmpathyCallWindow *self)
352 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
353 empathy_call_window_restart_call (self);
357 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
358 EmpathyCallWindow *self)
360 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
361 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
362 empathy_call_window_restart_call (self);
366 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
368 EmpathyCallWindow *self)
373 g_object_get (self->priv->handler, "call-channel", &call, NULL);
375 tones[0] = tp_dtmf_event_to_char (event);
377 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
379 g_object_unref (call);
383 empathy_call_window_show_video_output (EmpathyCallWindow *self,
386 if (self->priv->video_output != NULL)
387 g_object_set (self->priv->video_output, "visible", show, NULL);
389 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
391 clutter_actor_raise_top (self->priv->overlay_bin);
395 create_video_output_widget (EmpathyCallWindow *self)
397 EmpathyCallWindowPriv *priv = GET_PRIV (self);
399 g_assert (priv->video_output == NULL);
400 g_assert (priv->pipeline != NULL);
402 priv->video_output = clutter_texture_new ();
404 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
407 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
408 if (priv->video_output_sink == NULL)
409 g_error ("Missing cluttersink");
411 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
413 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
416 gtk_widget_add_events (priv->video_container,
417 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
418 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
419 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
423 create_video_input (EmpathyCallWindow *self)
425 EmpathyCallWindowPriv *priv = GET_PRIV (self);
427 g_assert (priv->video_input == NULL);
428 priv->video_input = empathy_video_src_new ();
429 gst_object_ref_sink (priv->video_input);
433 audio_control_volume_to_element (GBinding *binding,
434 const GValue *source_value,
435 GValue *target_value,
438 /* AudioControl volume is 0-255, with -1 for unknown */
441 hv = g_value_get_int (source_value);
446 g_value_set_double (target_value, hv/255.0);
452 element_volume_to_audio_control (GBinding *binding,
453 const GValue *source_value,
454 GValue *target_value,
459 ev = g_value_get_double (source_value);
460 ev = CLAMP (ev, 0.0, 1.0);
462 g_value_set_int (target_value, ev * 255);
467 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
468 EmpathyCallWindow *self)
471 g_object_get (obj, "mute", &muted, NULL);
473 self->priv->muted = muted;
474 if (muted && self->priv->transitions)
475 clutter_state_set_state (self->priv->transitions, "fade-in");
479 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
480 EMPATHY_IMAGE_MIC_MUTED, GTK_ICON_SIZE_MENU);
484 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
485 EMPATHY_IMAGE_MIC, GTK_ICON_SIZE_MENU);
488 empathy_call_window_update_timer (self);
492 create_audio_input (EmpathyCallWindow *self)
494 EmpathyCallWindowPriv *priv = GET_PRIV (self);
496 g_assert (priv->audio_input == NULL);
497 priv->audio_input = empathy_audio_src_new ();
498 gst_object_ref_sink (priv->audio_input);
500 g_signal_connect (priv->audio_input, "notify::mute",
501 G_CALLBACK (audio_input_mute_notify_cb), self);
505 add_video_preview_to_pipeline (EmpathyCallWindow *self)
507 EmpathyCallWindowPriv *priv = GET_PRIV (self);
510 g_assert (priv->video_preview != NULL);
511 g_assert (priv->pipeline != NULL);
512 g_assert (priv->video_input != NULL);
513 g_assert (priv->video_tee != NULL);
515 preview = priv->video_preview_sink;
517 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
519 g_warning ("Could not add video input to pipeline");
523 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
525 g_warning ("Could not add video preview to pipeline");
529 if (!gst_element_link (priv->video_input, priv->video_tee))
531 g_warning ("Could not link video input to video tee");
535 if (!gst_element_link (priv->video_tee, preview))
537 g_warning ("Could not link video tee to video preview");
543 empathy_call_window_disable_camera_cb (GtkAction *action,
544 EmpathyCallWindow *self)
546 clutter_actor_destroy (self->priv->preview_hidden_button);
548 gtk_toggle_button_set_active (
549 GTK_TOGGLE_BUTTON (self->priv->camera_button), FALSE);
553 empathy_call_window_minimise_camera_cb (GtkAction *action,
554 EmpathyCallWindow *self)
556 clutter_actor_hide (self->priv->video_preview);
557 clutter_actor_show (self->priv->preview_hidden_button);
561 empathy_call_window_maximise_camera_cb (GtkAction *action,
562 EmpathyCallWindow *self)
564 clutter_actor_show (self->priv->video_preview);
565 clutter_actor_hide (self->priv->preview_hidden_button);
569 empathy_call_window_swap_camera_cb (GtkAction *action,
570 EmpathyCallWindow *self)
572 const GList *cameras, *l;
575 DEBUG ("Swapping the camera");
577 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
578 current_cam = empathy_video_src_dup_device (
579 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
581 for (l = cameras; l != NULL; l = l->next)
583 EmpathyCamera *camera = l->data;
585 if (!tp_strdiff (camera->device, current_cam))
590 next = l->next->data;
592 next = cameras->data;
594 /* EmpathyCameraMenu will update itself and do the actual change
596 g_settings_set_string (self->priv->settings,
597 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
604 g_free (current_cam);
608 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
609 EmpathyCamera *camera,
610 EmpathyCallWindow *self)
612 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
614 gtk_action_set_visible (self->priv->menu_swap_camera,
615 g_list_length ((GList *) cameras) >= 2);
619 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
620 EmpathyCamera *camera,
621 EmpathyCallWindow *self)
623 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
625 gtk_action_set_visible (self->priv->menu_swap_camera,
626 g_list_length ((GList *) cameras) >= 2);
630 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
631 EmpathyCallWindow *self)
635 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
637 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
638 0, gtk_get_current_event_time ());
639 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
643 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
644 EmpathyCallWindow *self)
648 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
649 "/preview-hidden-menu");
650 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
651 0, gtk_get_current_event_time ());
652 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
655 static ClutterActor *
656 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
657 ClutterBinAlignment x,
658 ClutterBinAlignment y)
660 ClutterActor *rectangle;
662 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
663 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
664 PREVIEW_ROUND_FACTOR));
666 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
668 clutter_actor_hide (rectangle);
674 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
678 self->priv->preview_layout = clutter_bin_layout_new (
679 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
680 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
682 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
684 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
686 self->priv->preview_rectangle1 =
687 empathy_call_window_create_preview_rectangle (self,
688 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
689 self->priv->preview_rectangle2 =
690 empathy_call_window_create_preview_rectangle (self,
691 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
692 self->priv->preview_rectangle3 =
693 empathy_call_window_create_preview_rectangle (self,
694 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
695 self->priv->preview_rectangle4 =
696 empathy_call_window_create_preview_rectangle (self,
697 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
701 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
704 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
705 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
706 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
707 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
711 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
716 guint ret_x = 0, ret_y = 0;
719 if (!clutter_actor_has_allocation (self->priv->preview_box))
722 clutter_actor_get_geometry (self->priv->preview_box, &box);
726 case PREVIEW_POS_TOP_LEFT:
727 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
729 case PREVIEW_POS_TOP_RIGHT:
730 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
731 - SELF_VIDEO_SECTION_WIDTH;
732 ret_y = SELF_VIDEO_SECTION_MARGIN;
734 case PREVIEW_POS_BOTTOM_LEFT:
735 ret_x = SELF_VIDEO_SECTION_MARGIN;
736 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
737 - SELF_VIDEO_SECTION_HEIGHT;
739 case PREVIEW_POS_BOTTOM_RIGHT:
740 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
741 - SELF_VIDEO_SECTION_WIDTH;
742 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
743 - SELF_VIDEO_SECTION_HEIGHT;
746 g_warn_if_reached ();
757 static PreviewPosition
758 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
763 PreviewPosition pos = PREVIEW_POS_NONE;
765 if (!clutter_actor_has_allocation (self->priv->preview_box))
768 clutter_actor_get_geometry (self->priv->preview_box, &box);
770 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
771 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
772 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
773 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
775 pos = PREVIEW_POS_TOP_LEFT;
777 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
778 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
779 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
780 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
782 pos = PREVIEW_POS_TOP_RIGHT;
784 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
785 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
786 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
787 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
789 pos = PREVIEW_POS_BOTTOM_LEFT;
791 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
792 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
793 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
794 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
796 pos = PREVIEW_POS_BOTTOM_RIGHT;
802 static ClutterActor *
803 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
806 ClutterActor *rectangle;
810 case PREVIEW_POS_TOP_LEFT:
811 rectangle = self->priv->preview_rectangle1;
813 case PREVIEW_POS_TOP_RIGHT:
814 rectangle = self->priv->preview_rectangle3;
816 case PREVIEW_POS_BOTTOM_LEFT:
817 rectangle = self->priv->preview_rectangle2;
819 case PREVIEW_POS_BOTTOM_RIGHT:
820 rectangle = self->priv->preview_rectangle4;
830 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
833 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
835 DEBUG ("moving the video preview to %d", pos);
837 self->priv->preview_pos = pos;
841 case PREVIEW_POS_TOP_LEFT:
842 clutter_bin_layout_set_alignment (layout,
843 self->priv->video_preview,
844 CLUTTER_BIN_ALIGNMENT_START,
845 CLUTTER_BIN_ALIGNMENT_START);
847 case PREVIEW_POS_TOP_RIGHT:
848 clutter_bin_layout_set_alignment (layout,
849 self->priv->video_preview,
850 CLUTTER_BIN_ALIGNMENT_END,
851 CLUTTER_BIN_ALIGNMENT_START);
853 case PREVIEW_POS_BOTTOM_LEFT:
854 clutter_bin_layout_set_alignment (layout,
855 self->priv->video_preview,
856 CLUTTER_BIN_ALIGNMENT_START,
857 CLUTTER_BIN_ALIGNMENT_END);
859 case PREVIEW_POS_BOTTOM_RIGHT:
860 clutter_bin_layout_set_alignment (layout,
861 self->priv->video_preview,
862 CLUTTER_BIN_ALIGNMENT_END,
863 CLUTTER_BIN_ALIGNMENT_END);
866 g_warn_if_reached ();
869 g_settings_set_enum (self->priv->settings, "camera-position", pos);
873 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
876 ClutterActor *rectangle;
877 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
879 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
881 empathy_rounded_rectangle_set_border_width (
882 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
883 empathy_rounded_rectangle_set_border_color (
884 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
888 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
889 ClutterActor *rectangle)
891 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
893 clutter_color_shade (&white, 0.55, &darker);
895 empathy_rounded_rectangle_set_border_width (
896 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
897 empathy_rounded_rectangle_set_border_color (
898 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
902 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
904 ClutterActor *rectangle;
906 rectangle = empathy_call_window_get_preview_rectangle (self,
907 self->priv->preview_pos);
909 /* We don't want to darken the rectangle where the preview
912 if (self->priv->preview_rectangle1 != rectangle)
913 empathy_call_window_darken_preview_rectangle (self,
914 self->priv->preview_rectangle1);
916 if (self->priv->preview_rectangle2 != rectangle)
917 empathy_call_window_darken_preview_rectangle (self,
918 self->priv->preview_rectangle2);
920 if (self->priv->preview_rectangle3 != rectangle)
921 empathy_call_window_darken_preview_rectangle (self,
922 self->priv->preview_rectangle3);
924 if (self->priv->preview_rectangle4 != rectangle)
925 empathy_call_window_darken_preview_rectangle (self,
926 self->priv->preview_rectangle4);
930 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
934 ClutterModifierType modifiers,
935 EmpathyCallWindow *self)
937 ClutterActor *stage = clutter_actor_get_stage (actor);
940 self->priv->drag_preview = clutter_clone_new (actor);
942 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
943 self->priv->drag_preview);
945 clutter_actor_transform_stage_point (actor, event_x, event_y,
948 clutter_actor_set_position (self->priv->drag_preview,
949 event_x - rel_x, event_y - rel_y);
951 clutter_drag_action_set_drag_handle (action,
952 self->priv->drag_preview);
954 clutter_actor_set_opacity (actor, 0);
955 clutter_actor_hide (self->priv->preview_shown_button);
957 empathy_call_window_show_preview_rectangles (self, TRUE);
958 empathy_call_window_darken_preview_rectangles (self);
962 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
965 clutter_actor_set_opacity (actor, 255);
969 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
973 ClutterModifierType modifiers,
974 EmpathyCallWindow *self)
979 /* Get the position before destroying the drag actor, otherwise the
980 * preview_box allocation won't be valid and we won't be able to
981 * calculate the position. */
982 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
984 empathy_call_window_get_preview_coordinates (self,
985 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
988 /* Move the preview to the destination and destroy it afterwards */
989 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
992 "signal-swapped-after::completed",
993 clutter_actor_destroy, self->priv->drag_preview,
994 "signal-swapped-after::completed",
995 clutter_actor_show, self->priv->preview_shown_button,
997 empathy_call_window_on_animation_completed_cb, actor,
1000 self->priv->drag_preview = NULL;
1002 if (pos != PREVIEW_POS_NONE)
1003 empathy_call_window_move_video_preview (self, pos);
1005 empathy_call_window_show_preview_rectangles (self, FALSE);
1009 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1010 ClutterActor *actor,
1013 EmpathyCallWindow *self)
1015 PreviewPosition pos;
1016 gfloat event_x, event_y;
1018 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1020 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1022 if (pos != PREVIEW_POS_NONE)
1023 empathy_call_window_highlight_preview_rectangle (self, pos);
1025 empathy_call_window_darken_preview_rectangles (self);
1029 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1030 ClutterCrossingEvent *event,
1031 EmpathyCallWindow *self)
1033 ClutterActor *rectangle;
1035 rectangle = empathy_call_window_get_preview_rectangle (self,
1036 self->priv->preview_pos);
1038 empathy_call_window_highlight_preview_rectangle (self,
1039 self->priv->preview_pos);
1041 clutter_actor_show (rectangle);
1047 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1048 ClutterCrossingEvent *event,
1049 EmpathyCallWindow *self)
1051 ClutterActor *rectangle;
1053 rectangle = empathy_call_window_get_preview_rectangle (self,
1054 self->priv->preview_pos);
1056 empathy_call_window_darken_preview_rectangle (self, rectangle);
1058 clutter_actor_hide (rectangle);
1064 create_video_preview (EmpathyCallWindow *self)
1066 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1067 ClutterLayoutManager *layout;
1068 ClutterActor *preview;
1070 ClutterAction *action;
1072 PreviewPosition pos;
1074 g_assert (priv->video_preview == NULL);
1076 pos = g_settings_get_enum (priv->settings, "camera-position");
1078 preview = empathy_rounded_texture_new ();
1079 clutter_actor_set_size (preview,
1080 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1082 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1083 if (priv->video_preview_sink == NULL)
1084 g_error ("Missing cluttersink, check your clutter-gst installation");
1085 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1086 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1088 /* Add a little offset to the video preview */
1089 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1090 CLUTTER_BIN_ALIGNMENT_CENTER);
1091 priv->video_preview = clutter_box_new (layout);
1092 clutter_actor_set_size (priv->video_preview,
1093 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1094 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1096 /* Spinner for when changing the camera device */
1097 priv->preview_spinner_widget = gtk_spinner_new ();
1098 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1100 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1101 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1102 gtk_widget_show (priv->preview_spinner_widget);
1105 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1106 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1107 priv->preview_spinner_widget);
1108 clutter_actor_set_size (priv->preview_spinner_actor,
1109 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1110 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1111 clutter_actor_hide (priv->preview_spinner_actor);
1113 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1115 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1116 priv->preview_spinner_actor);
1118 g_object_set (priv->video_preview_sink,
1123 /* Translators: this is an "Info" label. It should be as short
1125 button = gtk_button_new_with_label (_("i"));
1126 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (button);
1127 clutter_actor_set_size (b, 24, 24);
1128 clutter_actor_set_margin_right (b, 4);
1129 clutter_actor_set_margin_bottom (b, 2);
1130 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1132 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1133 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1135 g_signal_connect (button, "clicked",
1136 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1139 /* Translators: this is an "Info" label. It should be as short
1141 button = gtk_button_new_with_label (_("i"));
1142 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (button);
1143 clutter_actor_set_size (b, 24, 24);
1144 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1146 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1147 priv->preview_hidden_button,
1148 CLUTTER_BIN_ALIGNMENT_START,
1149 CLUTTER_BIN_ALIGNMENT_END);
1151 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1153 clutter_actor_hide (priv->preview_hidden_button);
1155 g_signal_connect (button, "clicked",
1156 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1159 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1160 priv->video_preview,
1161 CLUTTER_BIN_ALIGNMENT_START,
1162 CLUTTER_BIN_ALIGNMENT_END);
1164 empathy_call_window_move_video_preview (self, pos);
1166 action = clutter_drag_action_new ();
1167 g_signal_connect (action, "drag-begin",
1168 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1169 g_signal_connect (action, "drag-end",
1170 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1171 g_signal_connect (action, "drag-motion",
1172 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1174 g_signal_connect (preview, "enter-event",
1175 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1176 g_signal_connect (preview, "leave-event",
1177 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1179 clutter_actor_add_action (preview, action);
1180 clutter_actor_set_reactive (preview, TRUE);
1181 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1185 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1187 clutter_actor_show (self->priv->preview_spinner_actor);
1188 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1192 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1194 clutter_actor_hide (self->priv->preview_spinner_actor);
1195 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1199 empathy_call_window_play_camera (EmpathyCallWindow *self,
1202 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1203 GstElement *preview;
1206 if (priv->video_preview == NULL)
1208 create_video_preview (self);
1209 add_video_preview_to_pipeline (self);
1214 state = GST_STATE_PLAYING;
1218 empathy_call_window_start_camera_spinning (self);
1219 state = GST_STATE_NULL;
1222 preview = priv->video_preview_sink;
1224 gst_element_set_state (preview, state);
1225 gst_element_set_state (priv->video_tee, state);
1226 gst_element_set_state (priv->video_input, state);
1230 display_video_preview (EmpathyCallWindow *self,
1233 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1235 if (priv->video_preview == NULL)
1237 create_video_preview (self);
1238 add_video_preview_to_pipeline (self);
1243 /* Display the video preview */
1244 DEBUG ("Show video preview");
1246 empathy_call_window_play_camera (self, TRUE);
1247 clutter_actor_show (priv->video_preview);
1248 clutter_actor_raise_top (priv->floating_toolbar);
1252 /* Hide the video preview */
1253 DEBUG ("Hide video preview");
1255 if (priv->video_preview != NULL)
1257 clutter_actor_hide (priv->video_preview);
1258 empathy_call_window_play_camera (self, FALSE);
1264 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1266 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1268 empathy_call_window_status_message (window, _("Connecting…"));
1269 priv->call_state = CONNECTING;
1271 /* Show the toolbar */
1272 clutter_state_set_state (priv->transitions, "fade-in");
1275 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1276 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1280 disable_camera (EmpathyCallWindow *self)
1282 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1284 if (priv->camera_state == CAMERA_STATE_OFF)
1287 DEBUG ("Disable camera");
1289 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1291 priv->camera_state = CAMERA_STATE_OFF;
1295 enable_camera (EmpathyCallWindow *self)
1297 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1299 if (priv->camera_state == CAMERA_STATE_ON)
1302 if (priv->video_input == NULL)
1304 DEBUG ("Can't enable camera, no input");
1308 DEBUG ("Enable camera");
1310 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1312 priv->camera_state = CAMERA_STATE_ON;
1316 empathy_call_window_camera_toggled_cb (GtkToggleButton *toggle,
1317 EmpathyCallWindow *self)
1319 if (gtk_toggle_button_get_active (toggle))
1320 enable_camera (self);
1322 disable_camera (self);
1326 create_pipeline (EmpathyCallWindow *self)
1328 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1331 g_assert (priv->pipeline == NULL);
1333 priv->pipeline = gst_pipeline_new (NULL);
1334 priv->pipeline_playing = FALSE;
1336 priv->video_tee = gst_element_factory_make ("tee", NULL);
1337 gst_object_ref_sink (priv->video_tee);
1339 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1341 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1342 priv->bus_message_source_id = gst_bus_add_watch (bus,
1343 empathy_call_window_bus_message, self);
1345 g_object_unref (bus);
1349 empathy_call_window_settings_cb (GtkAction *action,
1350 EmpathyCallWindow *self)
1352 gchar *args = g_strdup_printf ("-p %s",
1353 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1355 empathy_launch_program (BIN_DIR, "empathy", args);
1361 empathy_call_window_contents_cb (GtkAction *action,
1362 EmpathyCallWindow *self)
1364 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1368 empathy_call_window_debug_cb (GtkAction *action,
1369 EmpathyCallWindow *self)
1371 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1375 empathy_call_window_about_cb (GtkAction *action,
1376 EmpathyCallWindow *self)
1378 empathy_about_dialog_new (GTK_WINDOW (self));
1382 empathy_call_window_toolbar_timeout (gpointer data)
1384 EmpathyCallWindow *self = data;
1386 /* We don't want to hide the toolbar if we're not in a call, as
1387 * to show the call status all the time. Also don't hide if we're muted
1388 * to prevent the awkward, talking when muted situation */
1389 if (self->priv->call_state != CONNECTING &&
1390 self->priv->call_state != DISCONNECTED &&
1392 clutter_state_set_state (self->priv->transitions, "fade-out");
1398 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1400 EmpathyCallWindow *self)
1402 clutter_state_set_state (self->priv->transitions, "fade-in");
1404 if (self->priv->inactivity_src > 0)
1405 g_source_remove (self->priv->inactivity_src);
1407 self->priv->inactivity_src = g_timeout_add_seconds (3,
1408 empathy_call_window_toolbar_timeout, self);
1414 empathy_call_window_configure_event_cb (GtkWidget *widget,
1416 EmpathyCallWindow *self)
1418 GdkWindow *gdk_window;
1419 GdkWindowState window_state;
1421 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1422 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1424 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1425 &self->priv->dialpad_width, NULL);
1427 gdk_window = gtk_widget_get_window (widget);
1428 window_state = gdk_window_get_state (gdk_window);
1429 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1435 empathy_call_window_destroyed_cb (GtkWidget *object,
1436 EmpathyCallWindow *self)
1438 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1440 /* Save the geometry as if the dialpad was hidden. */
1441 empathy_geometry_save_values (GTK_WINDOW (self),
1442 self->priv->x, self->priv->y,
1443 self->priv->w - self->priv->dialpad_width, self->priv->h,
1444 self->priv->maximized);
1449 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1451 EmpathyCallWindow *self)
1453 switch (response_id)
1455 case GTK_RESPONSE_ACCEPT:
1456 tp_channel_dispatch_operation_handle_with_async (
1457 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1459 tp_clear_object (&self->priv->pending_cdo);
1460 tp_clear_object (&self->priv->pending_channel);
1461 tp_clear_object (&self->priv->pending_context);
1464 case GTK_RESPONSE_CANCEL:
1465 tp_channel_dispatch_operation_close_channels_async (
1466 self->priv->pending_cdo, NULL, NULL);
1468 empathy_call_window_status_message (self, _("Disconnected"));
1469 self->priv->call_state = DISCONNECTED;
1472 g_warn_if_reached ();
1477 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1481 g_assert (self->priv->call_state != CONNECTED);
1483 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1485 empathy_call_window_status_message (self, _("Incoming call"));
1486 self->priv->call_state = RINGING;
1488 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1489 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1490 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1491 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1492 empathy_contact_get_alias (self->priv->contact));
1494 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1495 _("Reject"), GTK_RESPONSE_CANCEL,
1496 _("Answer"), GTK_RESPONSE_ACCEPT,
1499 g_signal_connect (self->priv->incoming_call_dialog, "response",
1500 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1501 gtk_widget_show (self->priv->incoming_call_dialog);
1505 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1509 EmpathyCallWindow *self)
1511 tp_clear_object (&self->priv->pending_cdo);
1512 tp_clear_object (&self->priv->pending_channel);
1513 tp_clear_object (&self->priv->pending_context);
1515 /* We don't know if the incoming call has been accepted or not, so we
1516 * assume it hasn't and if it has, we'll set the proper status when
1517 * we get the new handler. */
1518 empathy_call_window_status_message (self, _("Disconnected"));
1519 self->priv->call_state = DISCONNECTED;
1521 gtk_widget_destroy (self->priv->incoming_call_dialog);
1522 self->priv->incoming_call_dialog = NULL;
1526 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1527 TpCallChannel *channel,
1528 TpChannelDispatchOperation *dispatch_operation,
1529 TpAddDispatchOperationContext *context)
1531 g_assert (self->priv->pending_channel == NULL);
1532 g_assert (self->priv->pending_context == NULL);
1533 g_assert (self->priv->pending_cdo == NULL);
1535 /* Start ringing and delay until the user answers or hangs. */
1536 self->priv->pending_channel = g_object_ref (channel);
1537 self->priv->pending_context = g_object_ref (context);
1538 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1540 g_signal_connect (self->priv->pending_cdo, "invalidated",
1541 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1543 empathy_call_window_set_state_ringing (self);
1544 tp_add_dispatch_operation_context_accept (context);
1548 mic_button_clicked (GtkWidget *button,
1549 EmpathyCallWindow *self)
1551 /* Toggle the muted state. We rely on audio_input_mute_notify_cb to update
1553 empathy_audio_src_set_mute (EMPATHY_GST_AUDIO_SRC (self->priv->audio_input),
1554 !self->priv->muted);
1558 empathy_call_window_init (EmpathyCallWindow *self)
1560 EmpathyCallWindowPriv *priv;
1562 GtkWidget *top_vbox;
1564 ClutterConstraint *constraint;
1565 ClutterActor *remote_avatar;
1566 ClutterColor black = { 0, 0, 0, 0 };
1567 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1568 OVERLAY_MARGIN, OVERLAY_MARGIN };
1570 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1571 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1573 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1574 priv->timer = g_timer_new ();
1576 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1577 gui = empathy_builder_get_file (filename,
1578 "call_window_vbox", &top_vbox,
1579 "errors_vbox", &priv->errors_vbox,
1580 "pane", &priv->pane,
1581 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1582 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1583 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1584 "status_label", &priv->status_label,
1585 "audiocall", &priv->audio_call_button,
1586 "videocall", &priv->video_call_button,
1587 "microphone", &priv->mic_button,
1588 "microphone_icon", &priv->microphone_icon,
1589 "volume", &priv->volume_button,
1590 "camera", &priv->camera_button,
1591 "hangup", &priv->hangup_button,
1592 "dialpad", &priv->dialpad_button,
1593 "toolbar", &priv->toolbar,
1594 "bottom_toolbar", &priv->bottom_toolbar,
1595 "ui_manager", &priv->ui_manager,
1596 "menufullscreen", &priv->menu_fullscreen,
1597 "menupreviewswap", &priv->menu_swap_camera,
1598 "details_vbox", &priv->details_vbox,
1599 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1600 "acodec_encoding_label", &priv->acodec_encoding_label,
1601 "acodec_decoding_label", &priv->acodec_decoding_label,
1602 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1603 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1604 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1605 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1606 "video_local_candidate_label", &priv->video_local_candidate_label,
1607 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1608 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1609 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1610 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1614 empathy_builder_connect (gui, self,
1615 "hangup", "clicked", empathy_call_window_hangup_cb,
1616 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1617 "videocall", "clicked", empathy_call_window_video_call_cb,
1618 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1619 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1620 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1621 "menusettings", "activate", empathy_call_window_settings_cb,
1622 "menucontents", "activate", empathy_call_window_contents_cb,
1623 "menudebug", "activate", empathy_call_window_debug_cb,
1624 "menuabout", "activate", empathy_call_window_about_cb,
1625 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1626 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1627 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1628 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1631 empathy_set_css_provider (GTK_WIDGET (self));
1632 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1634 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1636 g_object_bind_property (priv->camera_monitor, "available",
1637 priv->camera_button, "sensitive",
1638 G_BINDING_SYNC_CREATE);
1640 g_signal_connect (priv->camera_monitor, "added",
1641 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1642 g_signal_connect (priv->camera_monitor, "removed",
1643 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1645 g_signal_connect (priv->mic_button, "clicked",
1646 G_CALLBACK (mic_button_clicked), self);
1648 g_mutex_init (&priv->lock);
1650 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1652 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1653 CONTENT_HBOX_SPACING);
1654 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1657 /* main contents remote avatar/video box */
1658 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1659 CLUTTER_BIN_ALIGNMENT_FILL);
1661 priv->video_box = clutter_box_new (priv->video_layout);
1663 priv->video_container = gtk_clutter_embed_new ();
1665 gtk_widget_set_size_request (priv->video_container,
1666 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1668 /* Set the background black */
1669 clutter_stage_set_color (
1670 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1671 GTK_CLUTTER_EMBED (priv->video_container))),
1674 clutter_container_add (
1675 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1676 GTK_CLUTTER_EMBED (priv->video_container))),
1680 constraint = clutter_bind_constraint_new (
1681 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1682 CLUTTER_BIND_SIZE, 0);
1683 clutter_actor_add_constraint (priv->video_box, constraint);
1685 priv->remote_user_avatar_widget = gtk_image_new ();
1686 remote_avatar = gtk_clutter_actor_new_with_contents (
1687 priv->remote_user_avatar_widget);
1688 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1690 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1693 /* create the overlay bin */
1694 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1695 CLUTTER_BIN_ALIGNMENT_CENTER);
1696 priv->overlay_bin = clutter_actor_new ();
1697 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1699 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1701 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1703 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1705 empathy_call_window_create_preview_rectangles (self);
1707 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1708 priv->video_container, TRUE, TRUE,
1709 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1711 create_pipeline (self);
1712 create_video_output_widget (self);
1713 create_audio_input (self);
1714 create_video_input (self);
1716 priv->floating_toolbar = gtk_clutter_actor_new ();
1717 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1718 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1720 gtk_style_context_add_class (
1721 gtk_widget_get_style_context (GTK_WIDGET (priv->bottom_toolbar)),
1722 GTK_STYLE_CLASS_OSD);
1723 gtk_widget_reparent (priv->bottom_toolbar,
1724 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1726 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1727 priv->floating_toolbar,
1728 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1730 clutter_actor_raise_top (priv->floating_toolbar);
1732 /* Transitions for the floating toolbar */
1733 priv->transitions = clutter_state_new ();
1735 /* all transitions last for 2s */
1736 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1738 /* transition from any state to "fade-out" state */
1739 clutter_state_set (priv->transitions, NULL, "fade-out",
1740 priv->floating_toolbar,
1741 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1744 /* transition from any state to "fade-in" state */
1745 clutter_state_set (priv->transitions, NULL, "fade-in",
1746 priv->floating_toolbar,
1747 "opacity", CLUTTER_EASE_OUT_QUAD, 255,
1750 /* put the actor into the "fade-in" state with no animation */
1751 clutter_state_warp_to_state (priv->transitions, "fade-in");
1753 /* The call will be started as soon the pipeline is playing */
1754 priv->start_call_when_playing = TRUE;
1756 priv->dtmf_panel = empathy_dialpad_widget_new ();
1757 g_signal_connect (priv->dtmf_panel, "start-tone",
1758 G_CALLBACK (dtmf_start_tone_cb), self);
1760 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1763 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1766 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1768 gtk_widget_show_all (top_vbox);
1770 gtk_widget_hide (priv->dtmf_panel);
1771 gtk_widget_hide (priv->details_vbox);
1773 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1775 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1776 priv->video_container);
1778 /* We hide the bottom toolbar after 3s of inactivity and show it
1779 * again on mouse movement */
1780 priv->inactivity_src = g_timeout_add_seconds (3,
1781 empathy_call_window_toolbar_timeout, self);
1783 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1784 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1786 g_signal_connect (G_OBJECT (self), "realize",
1787 G_CALLBACK (empathy_call_window_realized_cb), self);
1789 g_signal_connect (G_OBJECT (self), "delete-event",
1790 G_CALLBACK (empathy_call_window_delete_cb), self);
1792 g_signal_connect (G_OBJECT (self), "window-state-event",
1793 G_CALLBACK (empathy_call_window_state_event_cb), self);
1795 g_signal_connect (G_OBJECT (self), "key-press-event",
1796 G_CALLBACK (empathy_call_window_key_press_cb), self);
1798 g_signal_connect (self, "motion-notify-event",
1799 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1801 g_object_ref (priv->ui_manager);
1802 g_object_unref (gui);
1804 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1805 priv->mic_menu = empathy_mic_menu_new (self);
1806 priv->camera_menu = empathy_camera_menu_new (self);
1808 empathy_call_window_show_hangup_button (self, TRUE);
1810 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1811 /* These signals are used to track the window position and save it
1812 * when the window is destroyed. We need to do this as we don't want
1813 * the window geometry to be saved with the dialpad taken into account. */
1814 g_signal_connect (self, "destroy",
1815 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1816 g_signal_connect (self, "configure-event",
1817 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1818 g_signal_connect (self, "window-state-event",
1819 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1821 /* Don't display labels in both toolbars */
1822 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1825 /* Instead of specifying a width and a height, we specify only one size. That's
1826 because we want a square avatar icon. */
1828 init_contact_avatar_with_size (EmpathyContact *contact,
1829 GtkWidget *image_widget,
1832 GdkPixbuf *pixbuf_avatar = NULL;
1834 if (contact != NULL)
1836 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1840 if (pixbuf_avatar == NULL)
1842 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1843 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1846 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1848 if (pixbuf_avatar != NULL)
1849 g_object_unref (pixbuf_avatar);
1853 set_window_title (EmpathyCallWindow *self)
1855 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1858 if (priv->contact != NULL)
1860 /* translators: Call is a noun and %s is the contact name. This string
1861 * is used in the window title */
1862 tmp = g_strdup_printf (_("Call with %s"),
1863 empathy_contact_get_alias (priv->contact));
1864 gtk_window_set_title (GTK_WINDOW (self), tmp);
1869 g_warning ("Unknown remote contact!");
1874 set_remote_user_name (EmpathyCallWindow *self,
1875 EmpathyContact *contact)
1877 const gchar *alias = empathy_contact_get_alias (contact);
1878 const gchar *status = empathy_contact_get_status (contact);
1880 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1882 if (status != NULL) {
1885 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1886 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1890 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1896 contact_name_changed_cb (EmpathyContact *contact,
1898 EmpathyCallWindow *self)
1900 set_window_title (self);
1901 set_remote_user_name (self, contact);
1905 contact_presence_changed_cb (EmpathyContact *contact,
1907 EmpathyCallWindow *self)
1909 set_remote_user_name (self, contact);
1913 contact_avatar_changed_cb (EmpathyContact *contact,
1915 EmpathyCallWindow *self)
1918 GtkAllocation allocation;
1919 GtkWidget *avatar_widget;
1921 avatar_widget = self->priv->remote_user_avatar_widget;
1923 gtk_widget_get_allocation (avatar_widget, &allocation);
1924 size = allocation.height;
1928 /* the widget is not allocated yet, set a default size */
1929 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1930 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1933 init_contact_avatar_with_size (contact, avatar_widget, size);
1935 avatar_widget = self->priv->remote_user_avatar_toolbar;
1937 gtk_widget_get_allocation (avatar_widget, &allocation);
1938 size = allocation.height;
1942 /* the widget is not allocated yet, set a default size */
1943 size = SMALL_TOOLBAR_SIZE;
1946 init_contact_avatar_with_size (contact, avatar_widget, size);
1950 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1951 EmpathyCallHandler *handler)
1953 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1955 tp_g_signal_connect_object (priv->contact, "notify::name",
1956 G_CALLBACK (contact_name_changed_cb), self, 0);
1957 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1958 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1959 tp_g_signal_connect_object (priv->contact, "notify::presence",
1960 G_CALLBACK (contact_presence_changed_cb), self, 0);
1962 set_window_title (self);
1963 set_remote_user_name (self, priv->contact);
1965 init_contact_avatar_with_size (priv->contact,
1966 priv->remote_user_avatar_widget,
1967 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1968 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1970 init_contact_avatar_with_size (priv->contact,
1971 priv->remote_user_avatar_toolbar,
1972 SMALL_TOOLBAR_SIZE);
1974 /* The remote avatar is shown by default and will be hidden when we receive
1975 video from the remote side. */
1976 clutter_actor_hide (priv->video_output);
1977 gtk_widget_show (priv->remote_user_avatar_widget);
1981 update_send_codec (EmpathyCallWindow *self,
1984 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1991 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1992 widget = priv->acodec_encoding_label;
1996 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1997 widget = priv->vcodec_encoding_label;
2003 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2004 gtk_label_set_text (GTK_LABEL (widget), tmp);
2009 send_audio_codec_notify_cb (GObject *object,
2013 EmpathyCallWindow *self = user_data;
2015 update_send_codec (self, TRUE);
2019 send_video_codec_notify_cb (GObject *object,
2023 EmpathyCallWindow *self = user_data;
2025 update_send_codec (self, FALSE);
2029 update_recv_codec (EmpathyCallWindow *self,
2032 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2035 GString *str = NULL;
2039 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2040 widget = priv->acodec_decoding_label;
2044 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2045 widget = priv->vcodec_decoding_label;
2051 for (l = codecs; l != NULL; l = g_list_next (l))
2053 FsCodec *codec = l->data;
2056 str = g_string_new (NULL);
2058 g_string_append (str, ", ");
2060 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2064 gtk_label_set_text (GTK_LABEL (widget), str->str);
2065 g_string_free (str, TRUE);
2069 recv_audio_codecs_notify_cb (GObject *object,
2073 EmpathyCallWindow *self = user_data;
2075 update_recv_codec (self, TRUE);
2079 recv_video_codecs_notify_cb (GObject *object,
2083 EmpathyCallWindow *self = user_data;
2085 update_recv_codec (self, FALSE);
2088 static const gchar *
2089 candidate_type_to_str (FsCandidate *candidate)
2091 switch (candidate->type)
2093 case FS_CANDIDATE_TYPE_HOST:
2095 case FS_CANDIDATE_TYPE_SRFLX:
2096 return "server reflexive";
2097 case FS_CANDIDATE_TYPE_PRFLX:
2098 return "peer reflexive";
2099 case FS_CANDIDATE_TYPE_RELAY:
2101 case FS_CANDIDATE_TYPE_MULTICAST:
2108 static const gchar *
2109 candidate_type_to_desc (FsCandidate *candidate)
2111 switch (candidate->type)
2113 case FS_CANDIDATE_TYPE_HOST:
2114 return _("The IP address as seen by the machine");
2115 case FS_CANDIDATE_TYPE_SRFLX:
2116 return _("The IP address as seen by a server on the Internet");
2117 case FS_CANDIDATE_TYPE_PRFLX:
2118 return _("The IP address of the peer as seen by the other side");
2119 case FS_CANDIDATE_TYPE_RELAY:
2120 return _("The IP address of a relay server");
2121 case FS_CANDIDATE_TYPE_MULTICAST:
2122 return _("The IP address of the multicast group");
2129 update_candidat_widget (EmpathyCallWindow *self,
2132 FsCandidate *candidate)
2136 g_assert (candidate != NULL);
2137 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2138 candidate->port, candidate_type_to_str (candidate));
2140 gtk_label_set_text (GTK_LABEL (label), str);
2141 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2147 candidates_changed_cb (GObject *object,
2149 EmpathyCallWindow *self)
2151 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2152 FsCandidate *candidate = NULL;
2154 if (type == FS_MEDIA_TYPE_VIDEO)
2156 /* Update remote candidate */
2157 candidate = empathy_call_handler_get_video_remote_candidate (
2160 update_candidat_widget (self, priv->video_remote_candidate_label,
2161 priv->video_remote_candidate_info_img, candidate);
2163 /* Update local candidate */
2164 candidate = empathy_call_handler_get_video_local_candidate (
2167 update_candidat_widget (self, priv->video_local_candidate_label,
2168 priv->video_local_candidate_info_img, candidate);
2172 /* Update remote candidate */
2173 candidate = empathy_call_handler_get_audio_remote_candidate (
2176 update_candidat_widget (self, priv->audio_remote_candidate_label,
2177 priv->audio_remote_candidate_info_img, candidate);
2179 /* Update local candidate */
2180 candidate = empathy_call_handler_get_audio_local_candidate (
2183 update_candidat_widget (self, priv->audio_local_candidate_label,
2184 priv->audio_local_candidate_info_img, candidate);
2189 empathy_call_window_constructed (GObject *object)
2191 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2192 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2193 TpCallChannel *call;
2196 g_assert (priv->handler != NULL);
2198 g_object_get (priv->handler, "call-channel", &call, NULL);
2199 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2200 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2201 tp_clear_object (&call);
2203 priv->contact = empathy_call_handler_get_contact (priv->handler);
2204 g_assert (priv->contact != NULL);
2205 g_object_ref (priv->contact);
2207 if (!empathy_contact_can_voip_video (priv->contact))
2209 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2210 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2213 empathy_call_window_setup_avatars (self, priv->handler);
2214 empathy_call_window_set_state_connecting (self);
2216 if (!empathy_call_handler_has_initial_video (priv->handler))
2218 gtk_toggle_button_set_active (
2219 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
2221 /* If call has InitialVideo, the preview will be started once the call has
2222 * been started (start_call()). */
2224 update_send_codec (self, TRUE);
2225 update_send_codec (self, FALSE);
2226 update_recv_codec (self, TRUE);
2227 update_recv_codec (self, FALSE);
2229 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2230 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2231 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2232 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2233 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2234 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2235 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2236 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2238 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2239 G_CALLBACK (candidates_changed_cb), self, 0);
2242 static void empathy_call_window_dispose (GObject *object);
2243 static void empathy_call_window_finalize (GObject *object);
2246 empathy_call_window_set_property (GObject *object,
2247 guint property_id, const GValue *value, GParamSpec *pspec)
2249 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2251 switch (property_id)
2253 case PROP_CALL_HANDLER:
2254 priv->handler = g_value_dup_object (value);
2257 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2262 empathy_call_window_get_property (GObject *object,
2263 guint property_id, GValue *value, GParamSpec *pspec)
2265 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2267 switch (property_id)
2269 case PROP_CALL_HANDLER:
2270 g_value_set_object (value, priv->handler);
2273 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2278 empathy_call_window_class_init (
2279 EmpathyCallWindowClass *empathy_call_window_class)
2281 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2282 GParamSpec *param_spec;
2284 g_type_class_add_private (empathy_call_window_class,
2285 sizeof (EmpathyCallWindowPriv));
2287 object_class->constructed = empathy_call_window_constructed;
2288 object_class->set_property = empathy_call_window_set_property;
2289 object_class->get_property = empathy_call_window_get_property;
2291 object_class->dispose = empathy_call_window_dispose;
2292 object_class->finalize = empathy_call_window_finalize;
2294 param_spec = g_param_spec_object ("handler",
2295 "handler", "The call handler",
2296 EMPATHY_TYPE_CALL_HANDLER,
2297 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2298 g_object_class_install_property (object_class,
2299 PROP_CALL_HANDLER, param_spec);
2303 empathy_call_window_dispose (GObject *object)
2305 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2306 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2308 if (priv->dispose_has_run)
2311 priv->dispose_has_run = TRUE;
2313 if (priv->handler != NULL)
2315 empathy_call_handler_stop_call (priv->handler);
2316 tp_clear_object (&priv->handler);
2319 if (priv->bus_message_source_id != 0)
2321 g_source_remove (priv->bus_message_source_id);
2322 priv->bus_message_source_id = 0;
2325 if (priv->got_video_src > 0)
2327 g_source_remove (priv->got_video_src);
2328 priv->got_video_src = 0;
2331 if (priv->inactivity_src > 0)
2333 g_source_remove (priv->inactivity_src);
2334 priv->inactivity_src = 0;
2337 tp_clear_object (&priv->pipeline);
2338 tp_clear_object (&priv->video_input);
2339 tp_clear_object (&priv->audio_input);
2340 tp_clear_object (&priv->video_tee);
2341 tp_clear_object (&priv->ui_manager);
2342 tp_clear_object (&priv->fullscreen);
2343 tp_clear_object (&priv->camera_monitor);
2344 tp_clear_object (&priv->settings);
2345 tp_clear_object (&priv->sound_mgr);
2346 tp_clear_object (&priv->mic_menu);
2347 tp_clear_object (&priv->camera_menu);
2348 tp_clear_object (&priv->transitions);
2350 g_list_free_full (priv->notifiers, g_object_unref);
2352 if (priv->timer_id != 0)
2353 g_source_remove (priv->timer_id);
2356 tp_clear_object (&priv->contact);
2358 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2362 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2364 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2366 if (priv->video_output_motion_handler_id != 0)
2368 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2369 priv->video_output_motion_handler_id);
2370 priv->video_output_motion_handler_id = 0;
2375 empathy_call_window_finalize (GObject *object)
2377 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2378 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2380 disconnect_video_output_motion_handler (self);
2382 /* free any data held directly by the object here */
2383 g_mutex_clear (&priv->lock);
2385 g_timer_destroy (priv->timer);
2387 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2392 empathy_call_window_new (EmpathyCallHandler *handler)
2394 return EMPATHY_CALL_WINDOW (
2395 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2399 empathy_call_window_present (EmpathyCallWindow *self,
2400 EmpathyCallHandler *handler)
2402 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2404 empathy_window_present (GTK_WINDOW (self));
2406 if (self->priv->call_state == DISCONNECTED)
2408 /* start a new call if one is not already in progress */
2409 tp_clear_object (&self->priv->handler);
2410 self->priv->handler = g_object_ref (handler);
2411 empathy_call_window_connect_handler (self);
2413 empathy_call_window_restart_call (self);
2418 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2419 GstElement *conference, gpointer user_data)
2421 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2422 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2423 FsElementAddedNotifier *notifier;
2426 DEBUG ("Conference added");
2428 /* Add notifier to set the various element properties as needed */
2429 notifier = fs_element_added_notifier_new ();
2430 keyfile = fs_utils_get_default_element_properties (conference);
2432 if (keyfile != NULL)
2433 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2435 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2437 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2439 gst_bin_add (GST_BIN (priv->pipeline), conference);
2440 gst_element_set_state (conference, GST_STATE_PLAYING);
2444 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2445 GstElement *conference, gpointer user_data)
2447 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2448 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2450 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2451 gst_element_set_state (conference, GST_STATE_NULL);
2455 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2457 GstStateChangeReturn state_change_return;
2458 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2460 if (priv->pipeline == NULL)
2463 if (priv->bus_message_source_id != 0)
2465 g_source_remove (priv->bus_message_source_id);
2466 priv->bus_message_source_id = 0;
2469 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2471 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2472 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2474 if (priv->pipeline != NULL)
2475 g_object_unref (priv->pipeline);
2476 priv->pipeline = NULL;
2478 if (priv->audio_output != NULL)
2479 g_object_unref (priv->audio_output);
2480 priv->audio_output = NULL;
2481 priv->audio_output_added = FALSE;
2483 if (priv->video_tee != NULL)
2484 g_object_unref (priv->video_tee);
2485 priv->video_tee = NULL;
2487 if (priv->video_preview != NULL)
2488 clutter_actor_destroy (priv->video_preview);
2489 priv->video_preview = NULL;
2491 /* If we destroy the preview while it's being dragged, we won't
2492 * get the ::drag-end signal, so manually destroy the clone */
2493 if (priv->drag_preview != NULL)
2495 clutter_actor_destroy (priv->drag_preview);
2496 empathy_call_window_show_preview_rectangles (self, FALSE);
2497 priv->drag_preview = NULL;
2500 priv->funnel = NULL;
2502 create_pipeline (self);
2503 /* Call will be started when user will hit the 'redial' button */
2504 priv->start_call_when_playing = FALSE;
2505 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2511 g_message ("Error: could not destroy pipeline. Closing call window");
2512 gtk_widget_destroy (GTK_WIDGET (self));
2519 reset_details_pane (EmpathyCallWindow *self)
2521 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2523 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2524 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2525 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2526 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2530 empathy_call_window_disconnected (EmpathyCallWindow *self,
2533 gboolean could_disconnect = FALSE;
2534 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2535 gboolean could_reset_pipeline;
2537 /* Leave full screen mode if needed */
2538 gtk_window_unfullscreen (GTK_WINDOW (self));
2540 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2541 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2543 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2545 if (priv->call_state == CONNECTING)
2546 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2548 if (priv->call_state != REDIALING)
2549 priv->call_state = DISCONNECTED;
2551 /* Show the toolbar */
2552 clutter_state_set_state (priv->transitions, "fade-in");
2554 if (could_reset_pipeline)
2556 g_mutex_lock (&priv->lock);
2558 g_timer_stop (priv->timer);
2560 if (priv->timer_id != 0)
2561 g_source_remove (priv->timer_id);
2564 g_mutex_unlock (&priv->lock);
2567 /* We are about to destroy the window, no need to update it or create
2568 * a video preview */
2571 empathy_call_window_status_message (self, _("Disconnected"));
2573 empathy_call_window_show_hangup_button (self, FALSE);
2575 /* Unsensitive the camera and mic button */
2576 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2577 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2579 /* Be sure that the mic button is enabled */
2580 empathy_audio_src_set_mute (
2581 EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), TRUE);
2583 if (priv->camera_state == CAMERA_STATE_ON)
2585 /* Restart the preview with the new pipeline. */
2586 display_video_preview (self, TRUE);
2589 /* destroy the video output; it will be recreated when we'll redial */
2590 disconnect_video_output_motion_handler (self);
2591 if (priv->video_output != NULL)
2592 clutter_actor_destroy (priv->video_output);
2593 priv->video_output = NULL;
2594 if (priv->got_video_src > 0)
2596 g_source_remove (priv->got_video_src);
2597 priv->got_video_src = 0;
2600 gtk_widget_show (priv->remote_user_avatar_widget);
2602 reset_details_pane (self);
2604 priv->sending_video = FALSE;
2605 priv->call_started = FALSE;
2607 could_disconnect = TRUE;
2609 /* TODO: display the self avatar of the preview (depends if the "Always
2610 * Show Video Preview" is enabled or not) */
2613 return could_disconnect;
2618 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2621 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2622 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2624 if (empathy_call_window_disconnected (self, TRUE) &&
2625 priv->call_state == REDIALING)
2626 empathy_call_window_restart_call (self);
2630 empathy_call_window_content_is_raw (TfContent *content)
2632 FsConference *conference;
2635 g_object_get (content, "fs-conference", &conference, NULL);
2636 g_assert (conference != NULL);
2638 /* FIXME: Ugly hack, update when moving a packetization property into
2640 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2641 gst_object_unref (conference);
2647 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2649 EmpathyCallWindow *self)
2651 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2652 FsMediaType media_type;
2654 DEBUG ("removing content");
2656 g_object_get (content, "media-type", &media_type, NULL);
2659 * This assumes that there is only one video stream per channel...
2662 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2664 if (priv->funnel != NULL)
2668 output = priv->video_output_sink;
2670 gst_element_set_state (output, GST_STATE_NULL);
2671 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2673 gst_bin_remove (GST_BIN (priv->pipeline), output);
2674 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2675 priv->funnel = NULL;
2678 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2680 if (priv->audio_output != NULL)
2682 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2684 if (priv->audio_output_added)
2685 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2686 priv->audio_output = NULL;
2687 priv->audio_output_added = FALSE;
2692 g_assert_not_reached ();
2699 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2701 EmpathyCallWindow *self)
2703 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2705 DEBUG ("Framerate changed to %u", framerate);
2707 if (priv->video_input != NULL)
2708 empathy_video_src_set_framerate (priv->video_input, framerate);
2712 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2715 EmpathyCallWindow *self)
2717 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2719 DEBUG ("Resolution changed to %ux%u", width, height);
2721 if (priv->video_input != NULL)
2723 empathy_video_src_set_resolution (priv->video_input, width, height);
2727 /* Called with global lock held */
2729 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2731 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2735 if (priv->funnel == NULL)
2737 output = priv->video_output_sink;
2739 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2743 g_warning ("Could not create fsfunnel");
2747 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2749 gst_object_unref (priv->funnel);
2750 priv->funnel = NULL;
2751 g_warning ("Could not add funnel to pipeline");
2755 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2757 g_warning ("Could not add the video output widget to the pipeline");
2761 if (!gst_element_link (priv->funnel, output))
2763 g_warning ("Could not link output sink to funnel");
2764 goto error_output_added;
2767 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2769 g_warning ("Could not start video sink");
2770 goto error_output_added;
2773 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2775 g_warning ("Could not start funnel");
2776 goto error_output_added;
2780 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2783 g_warning ("Could not get request pad from funnel");
2790 gst_element_set_locked_state (priv->funnel, TRUE);
2791 gst_element_set_locked_state (output, TRUE);
2793 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2794 gst_element_set_state (output, GST_STATE_NULL);
2796 gst_bin_remove (GST_BIN (priv->pipeline), output);
2797 gst_element_set_locked_state (output, FALSE);
2801 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2802 priv->funnel = NULL;
2807 /* Called with global lock held */
2809 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2812 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2814 GstPadTemplate *template;
2816 if (!priv->audio_output_added)
2818 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2820 g_warning ("Could not add audio sink to pipeline");
2821 g_object_unref (priv->audio_output);
2822 goto error_add_output;
2825 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2827 g_warning ("Could not start audio sink");
2832 template = gst_element_class_get_pad_template (
2833 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2835 pad = gst_element_request_pad (priv->audio_output,
2836 template, NULL, NULL);
2840 g_warning ("Could not get sink pad from sink");
2847 gst_element_set_locked_state (priv->audio_output, TRUE);
2848 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2849 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2850 priv->audio_output = NULL;
2858 empathy_call_window_update_timer (gpointer user_data)
2860 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2861 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2862 const gchar *status;
2866 time_ = g_timer_elapsed (priv->timer, NULL);
2868 if (priv->call_state == HELD)
2869 status = _("On hold");
2870 else if (priv->muted)
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_get_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_get_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_bin);
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 static GstPadProbeReturn
3260 empathy_call_window_video_probe_cb (GstPad *pad,
3261 GstPadProbeInfo *info,
3264 EmpathyCallWindow *self = user_data;
3266 if (G_UNLIKELY (!self->priv->got_video))
3268 /* show the remote video */
3269 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3270 empathy_call_window_show_video_output_cb,
3271 g_object_ref (self), g_object_unref);
3273 self->priv->got_video = TRUE;
3276 return GST_PAD_PROBE_OK;
3280 empathy_call_window_video_probe_cb (GstPad *pad,
3281 GstMiniObject *mini_obj,
3282 EmpathyCallWindow *self)
3285 if (GST_IS_EVENT (mini_obj))
3288 if (G_UNLIKELY (!self->priv->got_video))
3290 /* show the remote video */
3291 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3292 empathy_call_window_show_video_output_cb,
3293 g_object_ref (self), g_object_unref);
3295 self->priv->got_video = TRUE;
3302 /* Called from the streaming thread */
3304 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3305 TfContent *content, GstPad *src, gpointer user_data)
3307 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3308 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3309 gboolean retval = FALSE;
3314 g_mutex_lock (&priv->lock);
3316 g_object_get (content, "media-type", &media_type, NULL);
3320 case TP_MEDIA_STREAM_TYPE_AUDIO:
3321 pad = empathy_call_window_get_audio_sink_pad (self, content);
3323 case TP_MEDIA_STREAM_TYPE_VIDEO:
3324 g_idle_add (empathy_call_window_show_video_output_cb, self);
3325 pad = empathy_call_window_get_video_sink_pad (self);
3328 gst_pad_add_probe (src,
3329 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
3330 empathy_call_window_video_probe_cb, self, NULL);
3332 gst_pad_add_data_probe (src,
3333 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3335 if (priv->got_video_src > 0)
3336 g_source_remove (priv->got_video_src);
3337 priv->got_video_src = g_timeout_add_seconds (1,
3338 empathy_call_window_check_video_cb, self);
3341 g_assert_not_reached ();
3347 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3348 g_warning ("Could not link %s sink pad",
3349 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3353 gst_object_unref (pad);
3357 /* If no sink could be linked, try to add fakesink to prevent the whole call
3362 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3364 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3366 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3367 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3368 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3370 gst_element_set_locked_state (fakesink, TRUE);
3371 gst_element_set_state (fakesink, GST_STATE_NULL);
3372 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3376 DEBUG ("Could not link real sink, linked fakesink instead");
3378 gst_object_unref (sinkpad);
3382 gst_object_unref (fakesink);
3387 g_mutex_unlock (&priv->lock);
3393 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3396 EmpathyCallWindowPriv *priv = self->priv;
3398 g_assert (priv->audio_output_added == FALSE);
3399 g_assert (priv->audio_output == FALSE);
3401 priv->audio_output = empathy_audio_sink_new ();
3402 g_object_ref_sink (priv->audio_output);
3404 /* volume button to output volume linking */
3405 g_object_bind_property (priv->audio_output, "volume",
3406 priv->volume_button, "value",
3407 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3409 g_object_bind_property_full (content, "requested-output-volume",
3410 priv->audio_output, "volume",
3412 audio_control_volume_to_element,
3413 element_volume_to_audio_control,
3416 /* Link volumes together, sync the current audio input volume property
3417 * back to farstream first */
3418 g_object_bind_property_full (priv->audio_output, "volume",
3419 content, "reported-output-volume",
3420 G_BINDING_SYNC_CREATE,
3421 element_volume_to_audio_control,
3422 audio_control_volume_to_element,
3425 /* For raw audio conferences assume that the producer of the raw data
3426 * has already processed it, so turn off any echo cancellation and any
3427 * other audio improvements that come with it */
3428 empathy_audio_sink_set_echo_cancel (
3429 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3430 !empathy_call_window_content_is_raw (content));
3435 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3436 TfContent *content, gpointer user_data)
3438 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3439 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3441 FsMediaType media_type;
3442 gboolean retval = FALSE;
3444 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3445 g_assert (sink != NULL);
3449 case FS_MEDIA_TYPE_AUDIO:
3451 /* For raw audio conferences assume that the receiver of the raw data
3452 * wants it unprocessed, so turn off any echo cancellation and any
3453 * other audio improvements that come with it */
3454 empathy_audio_src_set_echo_cancel (
3455 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3456 !empathy_call_window_content_is_raw (content));
3458 /* Link volumes together, sync the current audio input volume property
3459 * back to farstream first */
3460 g_object_bind_property_full (content, "requested-input-volume",
3461 priv->audio_input, "volume",
3463 audio_control_volume_to_element,
3464 element_volume_to_audio_control,
3467 g_object_bind_property_full (priv->audio_input, "volume",
3468 content, "reported-input-volume",
3469 G_BINDING_SYNC_CREATE,
3470 element_volume_to_audio_control,
3471 audio_control_volume_to_element,
3474 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3476 g_warning ("Could not add audio source to pipeline");
3480 pad = gst_element_get_static_pad (priv->audio_input, "src");
3483 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3484 g_warning ("Could not get source pad from audio source");
3488 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3490 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3491 gst_object_unref (pad);
3492 g_warning ("Could not link audio source to farsight");
3495 gst_object_unref (pad);
3497 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3499 g_warning ("Could not start audio source");
3500 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3501 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3505 /* Prepare our audio output, not added yet though */
3506 empathy_call_window_prepare_audio_output (self, content);
3510 case FS_MEDIA_TYPE_VIDEO:
3511 if (priv->video_tee != NULL)
3514 pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
3516 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3518 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3520 g_warning ("Could not link video source input pipeline");
3523 gst_object_unref (pad);
3529 g_assert_not_reached ();
3532 gst_object_unref (sink);
3537 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3539 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3540 GstElement *preview;
3542 disable_camera (self);
3544 DEBUG ("remove video input");
3545 preview = priv->video_preview_sink;
3547 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3548 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3549 gst_element_set_state (preview, GST_STATE_NULL);
3551 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3554 g_object_unref (priv->video_input);
3555 priv->video_input = NULL;
3556 g_object_unref (priv->video_tee);
3557 priv->video_tee = NULL;
3558 clutter_actor_destroy (priv->video_preview);
3559 priv->video_preview = NULL;
3561 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3565 start_call (EmpathyCallWindow *self)
3567 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3569 priv->call_started = TRUE;
3570 empathy_call_handler_start_call (priv->handler,
3571 gtk_get_current_event_time ());
3573 if (empathy_call_handler_has_initial_video (priv->handler))
3575 TpCallChannel *call;
3578 g_object_get (priv->handler, "call-channel", &call, NULL);
3579 /* If the call channel isn't set yet we're requesting it, if we're
3580 * requesting it with initial video it should be PENDING_SEND when we get
3583 s = TP_SENDING_STATE_PENDING_SEND;
3585 s = empathy_call_channel_get_video_state (call);
3587 if (s == TP_SENDING_STATE_PENDING_SEND ||
3588 s == TP_SENDING_STATE_SENDING)
3590 /* Enable 'send video' buttons and display the preview */
3591 gtk_toggle_button_set_active (
3592 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3596 gtk_toggle_button_set_active (
3597 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3599 if (priv->video_preview == NULL)
3601 create_video_preview (self);
3602 add_video_preview_to_pipeline (self);
3607 g_object_unref (call);
3612 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3615 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3616 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3617 GstState newstate, pending;
3619 empathy_call_handler_bus_message (priv->handler, bus, message);
3621 switch (GST_MESSAGE_TYPE (message))
3623 case GST_MESSAGE_STATE_CHANGED:
3624 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3626 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3628 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3629 !priv->call_started)
3631 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3632 if (newstate == GST_STATE_PAUSED)
3634 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3635 priv->pipeline_playing = TRUE;
3637 if (priv->start_call_when_playing)
3641 if (priv->video_preview_sink != NULL &&
3642 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3644 gst_message_parse_state_changed (message, NULL, &newstate,
3647 if (newstate == GST_STATE_PLAYING &&
3648 pending == GST_STATE_VOID_PENDING)
3649 empathy_call_window_stop_camera_spinning (self);
3652 case GST_MESSAGE_ERROR:
3654 GError *error = NULL;
3655 GstElement *gst_error;
3659 gst_message_parse_error (message, &error, &debug);
3660 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3662 g_message ("Element error: %s -- %s\n", error->message, debug);
3664 name = gst_element_get_name (gst_error);
3665 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3667 /* Remove the video input and continue */
3668 if (priv->video_input != NULL)
3669 empathy_call_window_remove_video_input (self);
3670 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3674 empathy_call_window_disconnected (self, TRUE);
3677 g_error_free (error);
3680 case GST_MESSAGE_UNKNOWN:
3681 case GST_MESSAGE_EOS:
3682 case GST_MESSAGE_WARNING:
3683 case GST_MESSAGE_INFO:
3684 case GST_MESSAGE_TAG:
3685 case GST_MESSAGE_BUFFERING:
3686 case GST_MESSAGE_STATE_DIRTY:
3687 case GST_MESSAGE_STEP_DONE:
3688 case GST_MESSAGE_CLOCK_PROVIDE:
3689 case GST_MESSAGE_CLOCK_LOST:
3690 case GST_MESSAGE_NEW_CLOCK:
3691 case GST_MESSAGE_STRUCTURE_CHANGE:
3692 case GST_MESSAGE_STREAM_STATUS:
3693 case GST_MESSAGE_APPLICATION:
3694 case GST_MESSAGE_ELEMENT:
3695 case GST_MESSAGE_SEGMENT_START:
3696 case GST_MESSAGE_SEGMENT_DONE:
3697 case GST_MESSAGE_DURATION:
3698 case GST_MESSAGE_ANY:
3707 empathy_call_window_members_changed_cb (TpCallChannel *call,
3708 GHashTable *updates,
3710 TpCallStateReason *reason,
3711 EmpathyCallWindow *self)
3713 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3714 GHashTableIter iter;
3715 gpointer key, value;
3716 gboolean held = FALSE;
3718 g_hash_table_iter_init (&iter, updates);
3719 while (g_hash_table_iter_next (&iter, &key, &value))
3721 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3723 /* This assumes this is a 1-1 call, otherwise one participant
3724 * putting the call on hold wouldn't mean the call is on hold
3732 priv->call_state = HELD;
3733 else if (priv->call_state == HELD)
3734 priv->call_state = CONNECTED;
3738 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3740 EmpathyCallWindow *self)
3742 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3743 TpCallChannel *call;
3745 g_object_get (priv->handler, "call-channel", &call, NULL);
3750 tp_g_signal_connect_object (call, "audio-stream-error",
3751 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3752 tp_g_signal_connect_object (call, "video-stream-error",
3753 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3756 tp_g_signal_connect_object (call, "members-changed",
3757 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3759 g_object_unref (call);
3763 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3765 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3766 TpCallChannel *call;
3768 g_signal_connect (priv->handler, "state-changed",
3769 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3770 g_signal_connect (priv->handler, "conference-added",
3771 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3772 g_signal_connect (priv->handler, "conference-removed",
3773 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3774 g_signal_connect (priv->handler, "closed",
3775 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3776 g_signal_connect (priv->handler, "src-pad-added",
3777 G_CALLBACK (empathy_call_window_src_added_cb), self);
3778 g_signal_connect (priv->handler, "content-added",
3779 G_CALLBACK (empathy_call_window_content_added_cb), self);
3780 g_signal_connect (priv->handler, "content-removed",
3781 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3783 /* We connect to ::call-channel unconditionally since we'll
3784 * get new channels if we hangup and redial or if we reuse the
3786 g_signal_connect (priv->handler, "notify::call-channel",
3787 G_CALLBACK (call_handler_notify_call_cb), self);
3789 g_signal_connect (priv->handler, "framerate-changed",
3790 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3791 g_signal_connect (priv->handler, "resolution-changed",
3792 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3794 g_object_get (priv->handler, "call-channel", &call, NULL);
3797 /* We won't get notify::call-channel for this channel, so
3798 * directly call the callback. */
3799 call_handler_notify_call_cb (priv->handler, NULL, self);
3800 g_object_unref (call);
3805 empathy_call_window_realized_cb (GtkWidget *widget,
3806 EmpathyCallWindow *self)
3810 /* Make the hangup button twice as wide */
3811 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3812 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3814 empathy_call_window_connect_handler (self);
3816 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3820 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3821 EmpathyCallWindow *window)
3823 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3825 if (priv->pipeline != NULL)
3827 if (priv->bus_message_source_id != 0)
3829 g_source_remove (priv->bus_message_source_id);
3830 priv->bus_message_source_id = 0;
3833 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3836 if (priv->call_state == CONNECTING)
3837 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3843 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3846 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3848 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3853 gtk_widget_hide (priv->dtmf_panel);
3854 gtk_widget_hide (menu);
3855 gtk_widget_hide (priv->toolbar);
3859 if (priv->dialpad_was_visible_before_fs)
3860 gtk_widget_show (priv->dtmf_panel);
3862 gtk_widget_show (menu);
3863 gtk_widget_show (priv->toolbar);
3865 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3866 priv->original_height_before_fs);
3871 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3873 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3875 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3876 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3878 if (priv->video_output != NULL)
3881 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3882 priv->video_output, TRUE, TRUE,
3883 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3890 empathy_call_window_state_event_cb (GtkWidget *widget,
3891 GdkEventWindowState *event, EmpathyCallWindow *window)
3893 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3895 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3896 gboolean set_fullscreen = event->new_window_state &
3897 GDK_WINDOW_STATE_FULLSCREEN;
3901 gboolean dialpad_was_visible;
3902 GtkAllocation allocation;
3903 gint original_width, original_height;
3905 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3906 original_width = allocation.width;
3907 original_height = allocation.height;
3909 g_object_get (priv->dtmf_panel,
3910 "visible", &dialpad_was_visible,
3913 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3914 priv->original_width_before_fs = original_width;
3915 priv->original_height_before_fs = original_height;
3917 if (priv->video_output_motion_handler_id == 0 &&
3918 priv->video_output != NULL)
3920 priv->video_output_motion_handler_id = g_signal_connect (
3921 G_OBJECT (priv->video_container), "motion-notify-event",
3922 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3928 disconnect_video_output_motion_handler (window);
3931 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3933 show_controls (window, set_fullscreen);
3934 show_borders (window, set_fullscreen);
3935 gtk_action_set_stock_id (priv->menu_fullscreen,
3936 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3937 priv->is_fullscreen = set_fullscreen;
3944 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3947 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3948 int w, h, dialpad_width;
3949 GtkAllocation allocation;
3951 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3952 w = allocation.width;
3953 h = allocation.height;
3955 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3959 gtk_widget_show (priv->dtmf_panel);
3965 gtk_widget_hide (priv->dtmf_panel);
3969 gtk_window_resize (GTK_WINDOW (window), w, h);
3973 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3976 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3977 TpCallChannel *call;
3979 priv->sending_video = (state == CAMERA_STATE_ON);
3981 if (state == CAMERA_STATE_ON)
3983 /* When we start sending video, we want to show the video preview by
3985 display_video_preview (window, TRUE);
3989 display_video_preview (window, FALSE);
3992 if (priv->call_state != CONNECTED)
3995 g_object_get (priv->handler, "call-channel", &call, NULL);
3996 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3997 empathy_call_channel_send_video (call, priv->sending_video);
3998 g_object_unref (call);
4002 empathy_call_window_hangup_cb (gpointer object,
4003 EmpathyCallWindow *self)
4005 /* stopping the call will put it the ENDED state and
4006 * from state_changed_cb we'll reconfigure the window
4008 empathy_call_handler_stop_call (self->priv->handler);
4012 empathy_call_window_restart_call (EmpathyCallWindow *window)
4014 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4016 /* Remove error info bars */
4017 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4018 (GtkCallback) gtk_widget_destroy, NULL);
4020 create_video_output_widget (window);
4021 priv->outgoing = TRUE;
4022 empathy_call_window_set_state_connecting (window);
4024 if (priv->pipeline_playing)
4025 start_call (window);
4027 /* call will be started when the pipeline is ready */
4028 priv->start_call_when_playing = TRUE;
4030 empathy_call_window_setup_avatars (window, priv->handler);
4032 empathy_call_window_show_hangup_button (window, TRUE);
4036 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4037 EmpathyCallWindow *window)
4041 active = gtk_toggle_tool_button_get_active (button);
4043 empathy_call_window_show_dialpad (window, active);
4047 empathy_call_window_fullscreen_cb (gpointer object,
4048 EmpathyCallWindow *window)
4050 empathy_call_window_fullscreen_toggle (window);
4054 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4056 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4058 if (priv->is_fullscreen)
4059 gtk_window_unfullscreen (GTK_WINDOW (window));
4061 gtk_window_fullscreen (GTK_WINDOW (window));
4065 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4066 GdkEventButton *event, EmpathyCallWindow *window)
4068 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4070 empathy_call_window_video_menu_popup (window, event->button);
4078 empathy_call_window_key_press_cb (GtkWidget *video_output,
4079 GdkEventKey *event, EmpathyCallWindow *window)
4081 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4084 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4086 /* Since we are in fullscreen mode, toggling will bring us back to
4088 empathy_call_window_fullscreen_toggle (window);
4092 key = gdk_keyval_to_unicode (event->keyval);
4113 gtk_toggle_tool_button_set_active (
4114 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
4116 empathy_dialpad_widget_press_key (
4117 EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
4123 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4124 GdkEventMotion *event, EmpathyCallWindow *window)
4126 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4128 if (priv->is_fullscreen)
4130 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4132 /* Show the bottom toolbar */
4133 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4140 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4144 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4146 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4148 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4149 button, gtk_get_current_event_time ());
4150 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4154 empathy_call_window_status_message (EmpathyCallWindow *self,
4157 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4161 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4163 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4165 return priv->ui_manager;
4168 EmpathyGstAudioSrc *
4169 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4171 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4173 return (EmpathyGstAudioSrc *) priv->audio_input;
4176 EmpathyGstVideoSrc *
4177 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4179 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4183 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4184 const gchar *device)
4186 EmpathyGstVideoSrc *video;
4189 /* Restart the camera only if it's already running */
4190 running = (self->priv->video_preview != NULL);
4191 video = empathy_call_window_get_video_src (self);
4194 empathy_call_window_play_camera (self, FALSE);
4196 empathy_video_src_change_device (video, device);
4199 empathy_call_window_play_camera (self, TRUE);