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_BORDER_WIDTH 6
75 #define CONTENT_HBOX_SPACING 3
76 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
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 #define FLOATING_TOOLBAR_OPACITY 192
87 #define FLOATING_TOOLBAR_SPACING 20
89 /* The avatar's default width and height are set to the same value because we
90 want a square icon. */
91 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
92 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
94 #define SMALL_TOOLBAR_SIZE 36
96 /* If an video input error occurs, the error message will start with "v4l" */
97 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
99 /* The time interval in milliseconds between 2 outgoing rings */
100 #define MS_BETWEEN_RING 500
102 /* The roundedness of preview box and placeholders */
103 #define PREVIEW_ROUND_FACTOR 16
105 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
108 PROP_CALL_HANDLER = 1,
112 RINGING, /* Incoming call */
113 CONNECTING, /* Outgoing call */
114 CONNECTED, /* Connected */
115 HELD, /* Connected, but on hold */
116 DISCONNECTED, /* Disconnected */
117 REDIALING /* Redialing (special case of CONNECTING) */
121 CAMERA_STATE_OFF = 0,
127 PREVIEW_POS_TOP_LEFT,
128 PREVIEW_POS_TOP_RIGHT,
129 PREVIEW_POS_BOTTOM_LEFT,
130 PREVIEW_POS_BOTTOM_RIGHT,
133 struct _EmpathyCallWindowPriv
135 gboolean dispose_has_run;
136 EmpathyCallHandler *handler;
138 EmpathyContact *contact;
140 EmpathyCameraMonitor *camera_monitor;
145 GtkUIManager *ui_manager;
146 GtkWidget *errors_vbox;
147 /* widget displays the video received from the remote user. This widget is
148 * alive only during call. */
149 ClutterActor *video_output;
150 ClutterActor *video_preview;
151 ClutterActor *drag_preview;
152 ClutterActor *preview_shown_button;
153 ClutterActor *preview_hidden_button;
154 ClutterActor *preview_rectangle1;
155 ClutterActor *preview_rectangle2;
156 ClutterActor *preview_rectangle3;
157 ClutterActor *preview_rectangle4;
158 ClutterActor *preview_spinner_actor;
159 GtkWidget *preview_spinner_widget;
160 GtkWidget *video_container;
161 GtkWidget *remote_user_avatar_widget;
162 GtkWidget *remote_user_avatar_toolbar;
163 GtkWidget *remote_user_name_toolbar;
164 GtkWidget *status_label;
165 GtkWidget *hangup_button;
166 GtkWidget *audio_call_button;
167 GtkWidget *video_call_button;
168 GtkWidget *mic_button;
169 GtkWidget *volume_button;
170 GtkWidget *camera_button;
171 GtkWidget *dialpad_button;
173 GtkWidget *bottom_toolbar;
174 ClutterActor *floating_toolbar;
176 GtkAction *menu_fullscreen;
177 GtkAction *menu_swap_camera;
179 ClutterState *transitions;
181 /* The main box covering all the stage, contaning remote avatar/video */
182 ClutterActor *video_box;
183 ClutterLayoutManager *video_layout;
185 /* A Box layout manager containing a bin for previews
186 * and the floating toolbar */
187 ClutterActor *overlay_box;
188 ClutterLayoutManager *overlay_layout;
190 /* Bin layout for the previews */
191 ClutterActor *preview_box;
192 ClutterLayoutManager *preview_layout;
194 /* Coordinates of the preview drag event's start. */
195 PreviewPosition preview_pos;
197 /* We keep a reference on the hbox which contains the main content so we can
198 easilly repack everything when toggling fullscreen */
199 GtkWidget *content_hbox;
201 /* These are used to accept or reject an incoming call when the status
203 GtkWidget *incoming_call_dialog;
204 TpCallChannel *pending_channel;
205 TpChannelDispatchOperation *pending_cdo;
206 TpAddDispatchOperationContext *pending_context;
208 gulong video_output_motion_handler_id;
209 guint bus_message_source_id;
211 GtkWidget *dtmf_panel;
214 GtkWidget *details_vbox;
215 GtkWidget *vcodec_encoding_label;
216 GtkWidget *acodec_encoding_label;
217 GtkWidget *vcodec_decoding_label;
218 GtkWidget *acodec_decoding_label;
220 GtkWidget *audio_remote_candidate_label;
221 GtkWidget *audio_local_candidate_label;
222 GtkWidget *video_remote_candidate_label;
223 GtkWidget *video_local_candidate_label;
224 GtkWidget *video_remote_candidate_info_img;
225 GtkWidget *video_local_candidate_info_img;
226 GtkWidget *audio_remote_candidate_info_img;
227 GtkWidget *audio_local_candidate_info_img;
229 GstElement *video_input;
230 GstElement *video_preview_sink;
231 GstElement *video_output_sink;
232 GstElement *audio_input;
233 GstElement *audio_output;
234 gboolean audio_output_added;
235 GstElement *pipeline;
236 GstElement *video_tee;
246 gboolean call_started;
247 gboolean sending_video;
248 CameraState camera_state;
250 EmpathyCallWindowFullscreen *fullscreen;
251 gboolean is_fullscreen;
256 guint inactivity_src;
258 /* Those fields represent the state of the window before it actually was in
260 gboolean dialpad_was_visible_before_fs;
261 gint original_width_before_fs;
262 gint original_height_before_fs;
264 gint x, y, w, h, dialpad_width;
267 /* TRUE if the call should be started when the pipeline is playing */
268 gboolean start_call_when_playing;
269 /* TRUE if we requested to set the pipeline in the playing state */
270 gboolean pipeline_playing;
272 EmpathySoundManager *sound_mgr;
275 EmpathyMicMenu *mic_menu;
276 EmpathyCameraMenu *camera_menu;
279 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
281 static void empathy_call_window_realized_cb (GtkWidget *widget,
282 EmpathyCallWindow *window);
284 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
285 GdkEvent *event, EmpathyCallWindow *window);
287 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
288 GdkEventWindowState *event, EmpathyCallWindow *window);
290 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
293 static void empathy_call_window_hangup_cb (gpointer object,
294 EmpathyCallWindow *window);
296 static void empathy_call_window_fullscreen_cb (gpointer object,
297 EmpathyCallWindow *window);
299 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
301 static gboolean empathy_call_window_video_button_press_cb (
302 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
304 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
305 GdkEventKey *event, EmpathyCallWindow *window);
307 static gboolean empathy_call_window_video_output_motion_notify (
308 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
310 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
313 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
315 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
316 EmpathyCallWindow *window);
318 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
320 static void empathy_call_window_status_message (EmpathyCallWindow *window,
323 static gboolean empathy_call_window_bus_message (GstBus *bus,
324 GstMessage *message, gpointer user_data);
327 make_background_transparent (GtkClutterActor *actor)
329 GdkRGBA transparent = { 0., 0., 0., 0. };
332 widget = gtk_clutter_actor_get_widget (actor);
333 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
337 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
340 gtk_widget_set_visible (self->priv->hangup_button, show);
341 gtk_widget_set_visible (self->priv->audio_call_button, !show);
342 gtk_widget_set_visible (self->priv->video_call_button, !show);
346 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
347 EmpathyCallWindow *self)
349 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
350 empathy_call_window_restart_call (self);
354 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
355 EmpathyCallWindow *self)
357 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
358 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
359 empathy_call_window_restart_call (self);
363 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
365 EmpathyCallWindow *self)
370 g_object_get (self->priv->handler, "call-channel", &call, NULL);
372 tones[0] = tp_dtmf_event_to_char (event);
374 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
376 g_object_unref (call);
380 empathy_call_window_show_video_output (EmpathyCallWindow *self,
383 if (self->priv->video_output != NULL)
384 g_object_set (self->priv->video_output, "visible", show, NULL);
386 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
388 clutter_actor_raise_top (self->priv->overlay_box);
392 create_video_output_widget (EmpathyCallWindow *self)
394 EmpathyCallWindowPriv *priv = GET_PRIV (self);
396 g_assert (priv->video_output == NULL);
397 g_assert (priv->pipeline != NULL);
399 priv->video_output = clutter_texture_new ();
401 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
404 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
405 if (priv->video_output_sink == NULL)
406 g_error ("Missing cluttersink");
408 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
410 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
413 gtk_widget_add_events (priv->video_container,
414 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
415 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
416 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
420 create_video_input (EmpathyCallWindow *self)
422 EmpathyCallWindowPriv *priv = GET_PRIV (self);
424 g_assert (priv->video_input == NULL);
425 priv->video_input = empathy_video_src_new ();
426 gst_object_ref_sink (priv->video_input);
430 audio_control_volume_to_element (GBinding *binding,
431 const GValue *source_value,
432 GValue *target_value,
435 /* AudioControl volume is 0-255, with -1 for unknown */
438 hv = g_value_get_int (source_value);
443 g_value_set_double (target_value, hv/255.0);
449 element_volume_to_audio_control (GBinding *binding,
450 const GValue *source_value,
451 GValue *target_value,
456 ev = g_value_get_double (source_value);
457 ev = CLAMP (ev, 0.0, 1.0);
459 g_value_set_int (target_value, ev * 255);
464 create_audio_input (EmpathyCallWindow *self)
466 EmpathyCallWindowPriv *priv = GET_PRIV (self);
468 g_assert (priv->audio_input == NULL);
469 priv->audio_input = empathy_audio_src_new ();
470 gst_object_ref_sink (priv->audio_input);
472 g_object_bind_property (priv->mic_button, "active",
473 priv->audio_input, "mute",
474 G_BINDING_BIDIRECTIONAL |
475 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
479 add_video_preview_to_pipeline (EmpathyCallWindow *self)
481 EmpathyCallWindowPriv *priv = GET_PRIV (self);
484 g_assert (priv->video_preview != NULL);
485 g_assert (priv->pipeline != NULL);
486 g_assert (priv->video_input != NULL);
487 g_assert (priv->video_tee != NULL);
489 preview = priv->video_preview_sink;
491 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
493 g_warning ("Could not add video input to pipeline");
497 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
499 g_warning ("Could not add video preview to pipeline");
503 if (!gst_element_link (priv->video_input, priv->video_tee))
505 g_warning ("Could not link video input to video tee");
509 if (!gst_element_link (priv->video_tee, preview))
511 g_warning ("Could not link video tee to video preview");
517 empathy_call_window_disable_camera_cb (GtkAction *action,
518 EmpathyCallWindow *self)
520 clutter_actor_destroy (self->priv->preview_hidden_button);
522 gtk_toggle_tool_button_set_active (
523 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
527 empathy_call_window_minimise_camera_cb (GtkAction *action,
528 EmpathyCallWindow *self)
530 clutter_actor_hide (self->priv->video_preview);
531 clutter_actor_show (self->priv->preview_hidden_button);
535 empathy_call_window_maximise_camera_cb (GtkAction *action,
536 EmpathyCallWindow *self)
538 clutter_actor_show (self->priv->video_preview);
539 clutter_actor_hide (self->priv->preview_hidden_button);
543 empathy_call_window_swap_camera_cb (GtkAction *action,
544 EmpathyCallWindow *self)
546 const GList *cameras, *l;
549 DEBUG ("Swapping the camera");
551 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
552 current_cam = empathy_video_src_dup_device (
553 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
555 for (l = cameras; l != NULL; l = l->next)
557 EmpathyCamera *camera = l->data;
559 if (!tp_strdiff (camera->device, current_cam))
564 next = l->next->data;
566 next = cameras->data;
568 /* EmpathyCameraMenu will update itself and do the actual change
570 g_settings_set_string (self->priv->settings,
571 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
578 g_free (current_cam);
582 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
583 EmpathyCamera *camera,
584 EmpathyCallWindow *self)
586 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
588 gtk_action_set_visible (self->priv->menu_swap_camera,
589 g_list_length ((GList *) cameras) >= 2);
593 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
594 EmpathyCamera *camera,
595 EmpathyCallWindow *self)
597 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
599 gtk_action_set_visible (self->priv->menu_swap_camera,
600 g_list_length ((GList *) cameras) >= 2);
604 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
605 EmpathyCallWindow *self)
609 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
611 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
612 0, gtk_get_current_event_time ());
613 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
617 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
618 EmpathyCallWindow *self)
622 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
623 "/preview-hidden-menu");
624 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
625 0, gtk_get_current_event_time ());
626 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
629 static ClutterActor *
630 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
631 ClutterBinAlignment x,
632 ClutterBinAlignment y)
634 ClutterActor *rectangle;
636 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
637 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
638 PREVIEW_ROUND_FACTOR));
640 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
642 clutter_actor_hide (rectangle);
648 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
652 self->priv->preview_layout = clutter_bin_layout_new (
653 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
654 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
656 clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (self->priv->overlay_layout),
657 box, TRUE, TRUE, TRUE,
658 CLUTTER_BOX_ALIGNMENT_CENTER, CLUTTER_BOX_ALIGNMENT_START);
660 self->priv->preview_rectangle1 =
661 empathy_call_window_create_preview_rectangle (self,
662 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
663 self->priv->preview_rectangle2 =
664 empathy_call_window_create_preview_rectangle (self,
665 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
666 self->priv->preview_rectangle3 =
667 empathy_call_window_create_preview_rectangle (self,
668 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
669 self->priv->preview_rectangle4 =
670 empathy_call_window_create_preview_rectangle (self,
671 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
675 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
678 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
679 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
680 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
681 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
685 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
690 guint ret_x = 0, ret_y = 0;
693 if (!clutter_actor_has_allocation (self->priv->preview_box))
696 clutter_actor_get_geometry (self->priv->preview_box, &box);
700 case PREVIEW_POS_TOP_LEFT:
701 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
703 case PREVIEW_POS_TOP_RIGHT:
704 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
705 - SELF_VIDEO_SECTION_WIDTH;
706 ret_y = SELF_VIDEO_SECTION_MARGIN;
708 case PREVIEW_POS_BOTTOM_LEFT:
709 ret_x = SELF_VIDEO_SECTION_MARGIN;
710 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
711 - SELF_VIDEO_SECTION_HEIGHT;
713 case PREVIEW_POS_BOTTOM_RIGHT:
714 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
715 - SELF_VIDEO_SECTION_WIDTH;
716 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
717 - SELF_VIDEO_SECTION_HEIGHT;
720 g_warn_if_reached ();
731 static PreviewPosition
732 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
737 PreviewPosition pos = PREVIEW_POS_NONE;
739 if (!clutter_actor_has_allocation (self->priv->preview_box))
742 clutter_actor_get_geometry (self->priv->preview_box, &box);
744 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
745 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
746 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
747 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
749 pos = PREVIEW_POS_TOP_LEFT;
751 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
752 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
753 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
754 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
756 pos = PREVIEW_POS_TOP_RIGHT;
758 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
759 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
760 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
761 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
763 pos = PREVIEW_POS_BOTTOM_LEFT;
765 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
766 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
767 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
768 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
770 pos = PREVIEW_POS_BOTTOM_RIGHT;
776 static ClutterActor *
777 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
780 ClutterActor *rectangle;
784 case PREVIEW_POS_TOP_LEFT:
785 rectangle = self->priv->preview_rectangle1;
787 case PREVIEW_POS_TOP_RIGHT:
788 rectangle = self->priv->preview_rectangle3;
790 case PREVIEW_POS_BOTTOM_LEFT:
791 rectangle = self->priv->preview_rectangle2;
793 case PREVIEW_POS_BOTTOM_RIGHT:
794 rectangle = self->priv->preview_rectangle4;
804 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
807 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
809 DEBUG ("moving the video preview to %d", pos);
811 self->priv->preview_pos = pos;
815 case PREVIEW_POS_TOP_LEFT:
816 clutter_bin_layout_set_alignment (layout,
817 self->priv->video_preview,
818 CLUTTER_BIN_ALIGNMENT_START,
819 CLUTTER_BIN_ALIGNMENT_START);
821 case PREVIEW_POS_TOP_RIGHT:
822 clutter_bin_layout_set_alignment (layout,
823 self->priv->video_preview,
824 CLUTTER_BIN_ALIGNMENT_END,
825 CLUTTER_BIN_ALIGNMENT_START);
827 case PREVIEW_POS_BOTTOM_LEFT:
828 clutter_bin_layout_set_alignment (layout,
829 self->priv->video_preview,
830 CLUTTER_BIN_ALIGNMENT_START,
831 CLUTTER_BIN_ALIGNMENT_END);
833 case PREVIEW_POS_BOTTOM_RIGHT:
834 clutter_bin_layout_set_alignment (layout,
835 self->priv->video_preview,
836 CLUTTER_BIN_ALIGNMENT_END,
837 CLUTTER_BIN_ALIGNMENT_END);
840 g_warn_if_reached ();
843 g_settings_set_enum (self->priv->settings, "camera-position", pos);
847 _clutter_color_from_rgba (ClutterColor *color,
850 color->red = (guint8) floor (rgba->red * 255);
851 color->green = (guint8) floor (rgba->green * 255);
852 color->blue = (guint8) floor (rgba->blue * 255);
853 color->alpha = (guint8) floor (rgba->alpha * 255);
857 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
860 ClutterActor *rectangle;
861 GtkStyleContext *context;
863 ClutterColor color, highlight;
865 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
866 context = gtk_widget_get_style_context (GTK_WIDGET (self));
867 gtk_style_context_get_color (context, 0, &rgba);
869 _clutter_color_from_rgba (&color, &rgba);
870 clutter_color_shade (&color, 1.4, &highlight);
872 empathy_rounded_rectangle_set_border_width (
873 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
874 empathy_rounded_rectangle_set_border_color (
875 EMPATHY_ROUNDED_RECTANGLE (rectangle), &highlight);
879 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
880 ClutterActor *rectangle)
882 GtkStyleContext *context;
884 ClutterColor color, darker;
886 context = gtk_widget_get_style_context (GTK_WIDGET (self));
887 gtk_style_context_get_background_color (context, 0, &rgba);
889 _clutter_color_from_rgba (&color, &rgba);
890 clutter_color_shade (&color, 0.55, &darker);
892 empathy_rounded_rectangle_set_border_width (
893 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
894 empathy_rounded_rectangle_set_border_color (
895 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
899 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
901 ClutterActor *rectangle;
903 rectangle = empathy_call_window_get_preview_rectangle (self,
904 self->priv->preview_pos);
906 /* We don't want to darken the rectangle where the preview
909 if (self->priv->preview_rectangle1 != rectangle)
910 empathy_call_window_darken_preview_rectangle (self,
911 self->priv->preview_rectangle1);
913 if (self->priv->preview_rectangle2 != rectangle)
914 empathy_call_window_darken_preview_rectangle (self,
915 self->priv->preview_rectangle2);
917 if (self->priv->preview_rectangle3 != rectangle)
918 empathy_call_window_darken_preview_rectangle (self,
919 self->priv->preview_rectangle3);
921 if (self->priv->preview_rectangle4 != rectangle)
922 empathy_call_window_darken_preview_rectangle (self,
923 self->priv->preview_rectangle4);
927 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
931 ClutterModifierType modifiers,
932 EmpathyCallWindow *self)
934 ClutterActor *stage = clutter_actor_get_stage (actor);
937 self->priv->drag_preview = clutter_clone_new (actor);
939 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
940 self->priv->drag_preview);
942 clutter_actor_transform_stage_point (actor, event_x, event_y,
945 clutter_actor_set_position (self->priv->drag_preview,
946 event_x - rel_x, event_y - rel_y);
948 clutter_drag_action_set_drag_handle (action,
949 self->priv->drag_preview);
951 clutter_actor_set_opacity (actor, 0);
952 clutter_actor_hide (self->priv->preview_shown_button);
954 empathy_call_window_show_preview_rectangles (self, TRUE);
955 empathy_call_window_darken_preview_rectangles (self);
959 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
962 clutter_actor_set_opacity (actor, 255);
966 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
970 ClutterModifierType modifiers,
971 EmpathyCallWindow *self)
976 /* Get the position before destroying the drag actor, otherwise the
977 * preview_box allocation won't be valid and we won't be able to
978 * calculate the position. */
979 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
981 empathy_call_window_get_preview_coordinates (self,
982 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
985 /* Move the preview to the destination and destroy it afterwards */
986 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
989 "signal-swapped-after::completed",
990 clutter_actor_destroy, self->priv->drag_preview,
991 "signal-swapped-after::completed",
992 clutter_actor_show, self->priv->preview_shown_button,
994 empathy_call_window_on_animation_completed_cb, actor,
997 self->priv->drag_preview = NULL;
999 if (pos != PREVIEW_POS_NONE)
1000 empathy_call_window_move_video_preview (self, pos);
1002 empathy_call_window_show_preview_rectangles (self, FALSE);
1006 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1007 ClutterActor *actor,
1010 EmpathyCallWindow *self)
1012 PreviewPosition pos;
1013 gfloat event_x, event_y;
1015 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1017 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1019 if (pos != PREVIEW_POS_NONE)
1020 empathy_call_window_highlight_preview_rectangle (self, pos);
1022 empathy_call_window_darken_preview_rectangles (self);
1026 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1027 ClutterCrossingEvent *event,
1028 EmpathyCallWindow *self)
1030 ClutterActor *rectangle;
1032 rectangle = empathy_call_window_get_preview_rectangle (self,
1033 self->priv->preview_pos);
1035 empathy_call_window_highlight_preview_rectangle (self,
1036 self->priv->preview_pos);
1038 clutter_actor_show (rectangle);
1044 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1045 ClutterCrossingEvent *event,
1046 EmpathyCallWindow *self)
1048 ClutterActor *rectangle;
1050 rectangle = empathy_call_window_get_preview_rectangle (self,
1051 self->priv->preview_pos);
1053 empathy_call_window_darken_preview_rectangle (self, rectangle);
1055 clutter_actor_hide (rectangle);
1061 create_video_preview (EmpathyCallWindow *self)
1063 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1064 ClutterLayoutManager *layout;
1065 ClutterActor *preview;
1067 ClutterAction *action;
1069 PreviewPosition pos;
1071 g_assert (priv->video_preview == NULL);
1073 pos = g_settings_get_enum (priv->settings, "camera-position");
1075 preview = empathy_rounded_texture_new ();
1076 clutter_actor_set_size (preview,
1077 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1079 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1080 if (priv->video_preview_sink == NULL)
1081 g_error ("Missing cluttersink, check your clutter-gst installation");
1082 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1083 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1085 /* Add a little offset to the video preview */
1086 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1087 CLUTTER_BIN_ALIGNMENT_CENTER);
1088 priv->video_preview = clutter_box_new (layout);
1089 clutter_actor_set_size (priv->video_preview,
1090 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1091 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1093 /* Spinner for when changing the camera device */
1094 priv->preview_spinner_widget = gtk_spinner_new ();
1095 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1097 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1098 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1099 gtk_widget_show (priv->preview_spinner_widget);
1102 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1103 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1104 priv->preview_spinner_widget);
1105 clutter_actor_set_size (priv->preview_spinner_actor,
1106 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1107 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1108 clutter_actor_hide (priv->preview_spinner_actor);
1110 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1112 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1113 priv->preview_spinner_actor);
1115 g_object_set (priv->video_preview_sink,
1120 /* Translators: this is an "Info" label. It should be as short
1122 button = gtk_button_new_with_label (_("i"));
1123 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (button);
1124 clutter_actor_set_size (b, 24, 24);
1125 clutter_actor_set_margin_right (b, 4);
1126 clutter_actor_set_margin_bottom (b, 2);
1127 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1129 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1130 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1132 g_signal_connect (button, "clicked",
1133 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1136 /* Translators: this is an "Info" label. It should be as short
1138 button = gtk_button_new_with_label (_("i"));
1139 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (button);
1140 clutter_actor_set_size (b, 24, 24);
1141 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1143 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1144 priv->preview_hidden_button,
1145 CLUTTER_BIN_ALIGNMENT_START,
1146 CLUTTER_BIN_ALIGNMENT_END);
1148 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1150 clutter_actor_hide (priv->preview_hidden_button);
1152 g_signal_connect (button, "clicked",
1153 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1156 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1157 priv->video_preview,
1158 CLUTTER_BIN_ALIGNMENT_START,
1159 CLUTTER_BIN_ALIGNMENT_END);
1161 empathy_call_window_move_video_preview (self, pos);
1163 action = clutter_drag_action_new ();
1164 g_signal_connect (action, "drag-begin",
1165 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1166 g_signal_connect (action, "drag-end",
1167 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1168 g_signal_connect (action, "drag-motion",
1169 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1171 g_signal_connect (preview, "enter-event",
1172 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1173 g_signal_connect (preview, "leave-event",
1174 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1176 clutter_actor_add_action (preview, action);
1177 clutter_actor_set_reactive (preview, TRUE);
1178 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1182 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1184 clutter_actor_show (self->priv->preview_spinner_actor);
1185 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1189 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1191 clutter_actor_hide (self->priv->preview_spinner_actor);
1192 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1196 empathy_call_window_play_camera (EmpathyCallWindow *self,
1199 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1200 GstElement *preview;
1203 if (priv->video_preview == NULL)
1205 create_video_preview (self);
1206 add_video_preview_to_pipeline (self);
1211 state = GST_STATE_PLAYING;
1215 empathy_call_window_start_camera_spinning (self);
1216 state = GST_STATE_NULL;
1219 preview = priv->video_preview_sink;
1221 gst_element_set_state (preview, state);
1222 gst_element_set_state (priv->video_tee, state);
1223 gst_element_set_state (priv->video_input, state);
1227 display_video_preview (EmpathyCallWindow *self,
1230 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1232 if (priv->video_preview == NULL)
1234 create_video_preview (self);
1235 add_video_preview_to_pipeline (self);
1240 /* Display the video preview */
1241 DEBUG ("Show video preview");
1243 empathy_call_window_play_camera (self, TRUE);
1244 clutter_actor_show (priv->video_preview);
1245 clutter_actor_raise_top (priv->floating_toolbar);
1249 /* Hide the video preview */
1250 DEBUG ("Hide video preview");
1252 if (priv->video_preview != NULL)
1254 clutter_actor_hide (priv->video_preview);
1255 empathy_call_window_play_camera (self, FALSE);
1261 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1263 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1265 empathy_call_window_status_message (window, _("Connecting…"));
1266 priv->call_state = CONNECTING;
1268 /* Show the toolbar */
1269 clutter_state_set_state (priv->transitions, "fade-in");
1272 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1273 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1277 disable_camera (EmpathyCallWindow *self)
1279 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1281 if (priv->camera_state == CAMERA_STATE_OFF)
1284 DEBUG ("Disable camera");
1286 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1288 priv->camera_state = CAMERA_STATE_OFF;
1292 enable_camera (EmpathyCallWindow *self)
1294 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1296 if (priv->camera_state == CAMERA_STATE_ON)
1299 if (priv->video_input == NULL)
1301 DEBUG ("Can't enable camera, no input");
1305 DEBUG ("Enable camera");
1307 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1309 priv->camera_state = CAMERA_STATE_ON;
1313 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1314 EmpathyCallWindow *self)
1316 if (gtk_toggle_tool_button_get_active (toggle))
1317 enable_camera (self);
1319 disable_camera (self);
1323 create_pipeline (EmpathyCallWindow *self)
1325 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1328 g_assert (priv->pipeline == NULL);
1330 priv->pipeline = gst_pipeline_new (NULL);
1331 priv->pipeline_playing = FALSE;
1333 priv->video_tee = gst_element_factory_make ("tee", NULL);
1334 gst_object_ref_sink (priv->video_tee);
1336 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1338 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1339 priv->bus_message_source_id = gst_bus_add_watch (bus,
1340 empathy_call_window_bus_message, self);
1342 g_object_unref (bus);
1346 empathy_call_window_settings_cb (GtkAction *action,
1347 EmpathyCallWindow *self)
1349 gchar *args = g_strdup_printf ("-p %s",
1350 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1352 empathy_launch_program (BIN_DIR, "empathy", args);
1358 empathy_call_window_contents_cb (GtkAction *action,
1359 EmpathyCallWindow *self)
1361 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1365 empathy_call_window_debug_cb (GtkAction *action,
1366 EmpathyCallWindow *self)
1368 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1372 empathy_call_window_about_cb (GtkAction *action,
1373 EmpathyCallWindow *self)
1375 empathy_about_dialog_new (GTK_WINDOW (self));
1379 empathy_call_window_toolbar_timeout (gpointer data)
1381 EmpathyCallWindow *self = data;
1383 /* We don't want to hide the toolbar if we're not in a call, as
1384 * to show the call status all the time. */
1385 if (self->priv->call_state != CONNECTING &&
1386 self->priv->call_state != DISCONNECTED)
1387 clutter_state_set_state (self->priv->transitions, "fade-out");
1393 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1395 EmpathyCallWindow *self)
1397 clutter_state_set_state (self->priv->transitions, "fade-in");
1399 if (self->priv->inactivity_src > 0)
1400 g_source_remove (self->priv->inactivity_src);
1402 self->priv->inactivity_src = g_timeout_add_seconds (3,
1403 empathy_call_window_toolbar_timeout, self);
1409 empathy_call_window_configure_event_cb (GtkWidget *widget,
1411 EmpathyCallWindow *self)
1413 GdkWindow *gdk_window;
1414 GdkWindowState window_state;
1416 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1417 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1419 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1420 &self->priv->dialpad_width, NULL);
1422 gdk_window = gtk_widget_get_window (widget);
1423 window_state = gdk_window_get_state (gdk_window);
1424 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1430 empathy_call_window_destroyed_cb (GtkWidget *object,
1431 EmpathyCallWindow *self)
1433 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1435 /* Save the geometry as if the dialpad was hidden. */
1436 empathy_geometry_save_values (GTK_WINDOW (self),
1437 self->priv->x, self->priv->y,
1438 self->priv->w - self->priv->dialpad_width, self->priv->h,
1439 self->priv->maximized);
1444 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1446 EmpathyCallWindow *self)
1448 switch (response_id)
1450 case GTK_RESPONSE_ACCEPT:
1451 tp_channel_dispatch_operation_handle_with_async (
1452 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1454 tp_clear_object (&self->priv->pending_cdo);
1455 tp_clear_object (&self->priv->pending_channel);
1456 tp_clear_object (&self->priv->pending_context);
1459 case GTK_RESPONSE_CANCEL:
1460 tp_channel_dispatch_operation_close_channels_async (
1461 self->priv->pending_cdo, NULL, NULL);
1463 empathy_call_window_status_message (self, _("Disconnected"));
1464 self->priv->call_state = DISCONNECTED;
1467 g_warn_if_reached ();
1472 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1476 g_assert (self->priv->call_state != CONNECTED);
1478 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1480 empathy_call_window_status_message (self, _("Incoming call"));
1481 self->priv->call_state = RINGING;
1483 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1484 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1485 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1486 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1487 empathy_contact_get_alias (self->priv->contact));
1489 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1490 _("Reject"), GTK_RESPONSE_CANCEL,
1491 _("Answer"), GTK_RESPONSE_ACCEPT,
1494 g_signal_connect (self->priv->incoming_call_dialog, "response",
1495 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1496 gtk_widget_show (self->priv->incoming_call_dialog);
1500 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1504 EmpathyCallWindow *self)
1506 tp_clear_object (&self->priv->pending_cdo);
1507 tp_clear_object (&self->priv->pending_channel);
1508 tp_clear_object (&self->priv->pending_context);
1510 /* We don't know if the incoming call has been accepted or not, so we
1511 * assume it hasn't and if it has, we'll set the proper status when
1512 * we get the new handler. */
1513 empathy_call_window_status_message (self, _("Disconnected"));
1514 self->priv->call_state = DISCONNECTED;
1516 gtk_widget_destroy (self->priv->incoming_call_dialog);
1517 self->priv->incoming_call_dialog = NULL;
1521 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1522 TpCallChannel *channel,
1523 TpChannelDispatchOperation *dispatch_operation,
1524 TpAddDispatchOperationContext *context)
1526 g_assert (self->priv->pending_channel == NULL);
1527 g_assert (self->priv->pending_context == NULL);
1528 g_assert (self->priv->pending_cdo == NULL);
1530 /* Start ringing and delay until the user answers or hangs. */
1531 self->priv->pending_channel = g_object_ref (channel);
1532 self->priv->pending_context = g_object_ref (context);
1533 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1535 g_signal_connect (self->priv->pending_cdo, "invalidated",
1536 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1538 empathy_call_window_set_state_ringing (self);
1539 tp_add_dispatch_operation_context_accept (context);
1543 empathy_call_window_init (EmpathyCallWindow *self)
1545 EmpathyCallWindowPriv *priv;
1547 GtkWidget *top_vbox;
1549 ClutterConstraint *constraint;
1550 ClutterActor *remote_avatar;
1551 GtkStyleContext *context;
1552 GtkCssProvider *provider;
1556 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1557 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1559 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1561 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1562 gui = empathy_builder_get_file (filename,
1563 "call_window_vbox", &top_vbox,
1564 "errors_vbox", &priv->errors_vbox,
1565 "pane", &priv->pane,
1566 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1567 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1568 "status_label", &priv->status_label,
1569 "audiocall", &priv->audio_call_button,
1570 "videocall", &priv->video_call_button,
1571 "microphone", &priv->mic_button,
1572 "volume", &priv->volume_button,
1573 "camera", &priv->camera_button,
1574 "hangup", &priv->hangup_button,
1575 "dialpad", &priv->dialpad_button,
1576 "toolbar", &priv->toolbar,
1577 "bottom_toolbar", &priv->bottom_toolbar,
1578 "ui_manager", &priv->ui_manager,
1579 "menufullscreen", &priv->menu_fullscreen,
1580 "menupreviewswap", &priv->menu_swap_camera,
1581 "details_vbox", &priv->details_vbox,
1582 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1583 "acodec_encoding_label", &priv->acodec_encoding_label,
1584 "acodec_decoding_label", &priv->acodec_decoding_label,
1585 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1586 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1587 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1588 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1589 "video_local_candidate_label", &priv->video_local_candidate_label,
1590 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1591 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1592 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1593 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1597 empathy_builder_connect (gui, self,
1598 "hangup", "clicked", empathy_call_window_hangup_cb,
1599 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1600 "videocall", "clicked", empathy_call_window_video_call_cb,
1601 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1602 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1603 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1604 "menusettings", "activate", empathy_call_window_settings_cb,
1605 "menucontents", "activate", empathy_call_window_contents_cb,
1606 "menudebug", "activate", empathy_call_window_debug_cb,
1607 "menuabout", "activate", empathy_call_window_about_cb,
1608 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1609 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1610 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1611 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1614 /* FIXME: we should use a stock "OSD" style class for the toolbar,
1615 * once it's available in GTK+/Adwaita.
1617 provider = gtk_css_provider_new ();
1618 gtk_css_provider_load_from_data (provider,
1619 "#CallFloatingToolbar { border-radius: 6px; }", -1, NULL);
1620 gtk_style_context_add_provider (
1621 gtk_widget_get_style_context (priv->bottom_toolbar),
1622 GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1623 g_object_unref (provider);
1625 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1627 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1629 g_object_bind_property (priv->camera_monitor, "available",
1630 priv->camera_button, "sensitive",
1631 G_BINDING_SYNC_CREATE);
1633 g_signal_connect (priv->camera_monitor, "added",
1634 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1635 g_signal_connect (priv->camera_monitor, "removed",
1636 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1638 g_mutex_init (&priv->lock);
1640 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1642 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1643 CONTENT_HBOX_SPACING);
1644 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1645 CONTENT_HBOX_BORDER_WIDTH);
1646 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1649 /* main contents remote avatar/video box */
1650 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1651 CLUTTER_BIN_ALIGNMENT_CENTER);
1653 priv->video_box = clutter_box_new (priv->video_layout);
1655 priv->video_container = gtk_clutter_embed_new ();
1657 gtk_widget_set_size_request (priv->video_container,
1658 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1660 /* Set the background color to that of the rest of the window */
1661 context = gtk_widget_get_style_context (priv->content_hbox);
1662 gtk_style_context_get_background_color (context,
1663 GTK_STATE_FLAG_NORMAL, &rgba);
1664 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1665 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1666 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1667 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1668 clutter_stage_set_color (
1669 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1670 GTK_CLUTTER_EMBED (priv->video_container))),
1673 clutter_container_add (
1674 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1675 GTK_CLUTTER_EMBED (priv->video_container))),
1679 constraint = clutter_bind_constraint_new (
1680 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1681 CLUTTER_BIND_SIZE, 0);
1682 clutter_actor_add_constraint (priv->video_box, constraint);
1684 priv->remote_user_avatar_widget = gtk_image_new ();
1685 remote_avatar = gtk_clutter_actor_new_with_contents (
1686 priv->remote_user_avatar_widget);
1688 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1691 /* create the overlay box */
1692 priv->overlay_layout = clutter_box_layout_new ();
1693 clutter_box_layout_set_vertical (
1694 CLUTTER_BOX_LAYOUT (priv->overlay_layout), TRUE);
1695 priv->overlay_box = clutter_box_new (priv->overlay_layout);
1697 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1699 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1701 empathy_call_window_create_preview_rectangles (self);
1703 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1704 priv->video_container, TRUE, TRUE,
1705 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1707 create_pipeline (self);
1708 create_video_output_widget (self);
1709 create_audio_input (self);
1710 create_video_input (self);
1712 priv->floating_toolbar = gtk_clutter_actor_new ();
1713 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1714 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1716 gtk_widget_reparent (priv->bottom_toolbar,
1717 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1719 clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (priv->overlay_layout),
1720 priv->floating_toolbar, FALSE, FALSE, FALSE,
1721 CLUTTER_BOX_ALIGNMENT_CENTER, CLUTTER_BOX_ALIGNMENT_END);
1723 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1725 clutter_actor_raise_top (priv->floating_toolbar);
1727 /* Transitions for the floating toolbar */
1728 priv->transitions = clutter_state_new ();
1730 /* all transitions last for 2s */
1731 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1733 /* transition from any state to "fade-out" state */
1734 clutter_state_set (priv->transitions, NULL, "fade-out",
1735 priv->floating_toolbar,
1736 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1739 /* transition from any state to "fade-in" state */
1740 clutter_state_set (priv->transitions, NULL, "fade-in",
1741 priv->floating_toolbar,
1742 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1745 /* put the actor into the "fade-in" state with no animation */
1746 clutter_state_warp_to_state (priv->transitions, "fade-in");
1748 /* The call will be started as soon the pipeline is playing */
1749 priv->start_call_when_playing = TRUE;
1751 priv->dtmf_panel = empathy_dialpad_widget_new ();
1752 g_signal_connect (priv->dtmf_panel, "start-tone",
1753 G_CALLBACK (dtmf_start_tone_cb), self);
1755 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1758 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1761 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1763 gtk_widget_show_all (top_vbox);
1765 gtk_widget_hide (priv->dtmf_panel);
1766 gtk_widget_hide (priv->details_vbox);
1768 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1770 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1771 priv->video_container);
1773 /* We hide the bottom toolbar after 3s of inactivity and show it
1774 * again on mouse movement */
1775 priv->inactivity_src = g_timeout_add_seconds (3,
1776 empathy_call_window_toolbar_timeout, self);
1778 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1779 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1781 g_signal_connect (G_OBJECT (self), "realize",
1782 G_CALLBACK (empathy_call_window_realized_cb), self);
1784 g_signal_connect (G_OBJECT (self), "delete-event",
1785 G_CALLBACK (empathy_call_window_delete_cb), self);
1787 g_signal_connect (G_OBJECT (self), "window-state-event",
1788 G_CALLBACK (empathy_call_window_state_event_cb), self);
1790 g_signal_connect (G_OBJECT (self), "key-press-event",
1791 G_CALLBACK (empathy_call_window_key_press_cb), self);
1793 g_signal_connect (self, "motion-notify-event",
1794 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1796 priv->timer = g_timer_new ();
1798 g_object_ref (priv->ui_manager);
1799 g_object_unref (gui);
1801 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1802 priv->mic_menu = empathy_mic_menu_new (self);
1803 priv->camera_menu = empathy_camera_menu_new (self);
1805 empathy_call_window_show_hangup_button (self, TRUE);
1807 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1808 /* These signals are used to track the window position and save it
1809 * when the window is destroyed. We need to do this as we don't want
1810 * the window geometry to be saved with the dialpad taken into account. */
1811 g_signal_connect (self, "destroy",
1812 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1813 g_signal_connect (self, "configure-event",
1814 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1815 g_signal_connect (self, "window-state-event",
1816 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1818 /* Don't display labels in both toolbars */
1819 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1822 /* Instead of specifying a width and a height, we specify only one size. That's
1823 because we want a square avatar icon. */
1825 init_contact_avatar_with_size (EmpathyContact *contact,
1826 GtkWidget *image_widget,
1829 GdkPixbuf *pixbuf_avatar = NULL;
1831 if (contact != NULL)
1833 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1837 if (pixbuf_avatar == NULL)
1839 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1840 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1843 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1845 if (pixbuf_avatar != NULL)
1846 g_object_unref (pixbuf_avatar);
1850 set_window_title (EmpathyCallWindow *self)
1852 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1855 if (priv->contact != NULL)
1857 /* translators: Call is a noun and %s is the contact name. This string
1858 * is used in the window title */
1859 tmp = g_strdup_printf (_("Call with %s"),
1860 empathy_contact_get_alias (priv->contact));
1861 gtk_window_set_title (GTK_WINDOW (self), tmp);
1866 g_warning ("Unknown remote contact!");
1871 set_remote_user_name (EmpathyCallWindow *self,
1872 EmpathyContact *contact)
1874 const gchar *alias = empathy_contact_get_alias (contact);
1875 const gchar *status = empathy_contact_get_status (contact);
1878 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1879 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1885 contact_name_changed_cb (EmpathyContact *contact,
1887 EmpathyCallWindow *self)
1889 set_window_title (self);
1890 set_remote_user_name (self, contact);
1894 contact_presence_changed_cb (EmpathyContact *contact,
1896 EmpathyCallWindow *self)
1898 set_remote_user_name (self, contact);
1902 contact_avatar_changed_cb (EmpathyContact *contact,
1904 EmpathyCallWindow *self)
1907 GtkAllocation allocation;
1908 GtkWidget *avatar_widget;
1910 avatar_widget = self->priv->remote_user_avatar_widget;
1912 gtk_widget_get_allocation (avatar_widget, &allocation);
1913 size = allocation.height;
1917 /* the widget is not allocated yet, set a default size */
1918 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1919 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1922 init_contact_avatar_with_size (contact, avatar_widget, size);
1924 avatar_widget = self->priv->remote_user_avatar_toolbar;
1926 gtk_widget_get_allocation (avatar_widget, &allocation);
1927 size = allocation.height;
1931 /* the widget is not allocated yet, set a default size */
1932 size = SMALL_TOOLBAR_SIZE;
1935 init_contact_avatar_with_size (contact, avatar_widget, size);
1939 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1940 EmpathyCallHandler *handler)
1942 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1944 tp_g_signal_connect_object (priv->contact, "notify::name",
1945 G_CALLBACK (contact_name_changed_cb), self, 0);
1946 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1947 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1948 tp_g_signal_connect_object (priv->contact, "notify::presence",
1949 G_CALLBACK (contact_presence_changed_cb), self, 0);
1951 set_window_title (self);
1952 set_remote_user_name (self, priv->contact);
1954 init_contact_avatar_with_size (priv->contact,
1955 priv->remote_user_avatar_widget,
1956 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1957 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1959 init_contact_avatar_with_size (priv->contact,
1960 priv->remote_user_avatar_toolbar,
1961 SMALL_TOOLBAR_SIZE);
1963 /* The remote avatar is shown by default and will be hidden when we receive
1964 video from the remote side. */
1965 clutter_actor_hide (priv->video_output);
1966 gtk_widget_show (priv->remote_user_avatar_widget);
1970 update_send_codec (EmpathyCallWindow *self,
1973 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1980 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1981 widget = priv->acodec_encoding_label;
1985 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1986 widget = priv->vcodec_encoding_label;
1992 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1993 gtk_label_set_text (GTK_LABEL (widget), tmp);
1998 send_audio_codec_notify_cb (GObject *object,
2002 EmpathyCallWindow *self = user_data;
2004 update_send_codec (self, TRUE);
2008 send_video_codec_notify_cb (GObject *object,
2012 EmpathyCallWindow *self = user_data;
2014 update_send_codec (self, FALSE);
2018 update_recv_codec (EmpathyCallWindow *self,
2021 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2024 GString *str = NULL;
2028 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2029 widget = priv->acodec_decoding_label;
2033 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2034 widget = priv->vcodec_decoding_label;
2040 for (l = codecs; l != NULL; l = g_list_next (l))
2042 FsCodec *codec = l->data;
2045 str = g_string_new (NULL);
2047 g_string_append (str, ", ");
2049 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2053 gtk_label_set_text (GTK_LABEL (widget), str->str);
2054 g_string_free (str, TRUE);
2058 recv_audio_codecs_notify_cb (GObject *object,
2062 EmpathyCallWindow *self = user_data;
2064 update_recv_codec (self, TRUE);
2068 recv_video_codecs_notify_cb (GObject *object,
2072 EmpathyCallWindow *self = user_data;
2074 update_recv_codec (self, FALSE);
2077 static const gchar *
2078 candidate_type_to_str (FsCandidate *candidate)
2080 switch (candidate->type)
2082 case FS_CANDIDATE_TYPE_HOST:
2084 case FS_CANDIDATE_TYPE_SRFLX:
2085 return "server reflexive";
2086 case FS_CANDIDATE_TYPE_PRFLX:
2087 return "peer reflexive";
2088 case FS_CANDIDATE_TYPE_RELAY:
2090 case FS_CANDIDATE_TYPE_MULTICAST:
2097 static const gchar *
2098 candidate_type_to_desc (FsCandidate *candidate)
2100 switch (candidate->type)
2102 case FS_CANDIDATE_TYPE_HOST:
2103 return _("The IP address as seen by the machine");
2104 case FS_CANDIDATE_TYPE_SRFLX:
2105 return _("The IP address as seen by a server on the Internet");
2106 case FS_CANDIDATE_TYPE_PRFLX:
2107 return _("The IP address of the peer as seen by the other side");
2108 case FS_CANDIDATE_TYPE_RELAY:
2109 return _("The IP address of a relay server");
2110 case FS_CANDIDATE_TYPE_MULTICAST:
2111 return _("The IP address of the multicast group");
2118 update_candidat_widget (EmpathyCallWindow *self,
2121 FsCandidate *candidate)
2125 g_assert (candidate != NULL);
2126 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2127 candidate->port, candidate_type_to_str (candidate));
2129 gtk_label_set_text (GTK_LABEL (label), str);
2130 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2136 candidates_changed_cb (GObject *object,
2138 EmpathyCallWindow *self)
2140 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2141 FsCandidate *candidate = NULL;
2143 if (type == FS_MEDIA_TYPE_VIDEO)
2145 /* Update remote candidate */
2146 candidate = empathy_call_handler_get_video_remote_candidate (
2149 update_candidat_widget (self, priv->video_remote_candidate_label,
2150 priv->video_remote_candidate_info_img, candidate);
2152 /* Update local candidate */
2153 candidate = empathy_call_handler_get_video_local_candidate (
2156 update_candidat_widget (self, priv->video_local_candidate_label,
2157 priv->video_local_candidate_info_img, candidate);
2161 /* Update remote candidate */
2162 candidate = empathy_call_handler_get_audio_remote_candidate (
2165 update_candidat_widget (self, priv->audio_remote_candidate_label,
2166 priv->audio_remote_candidate_info_img, candidate);
2168 /* Update local candidate */
2169 candidate = empathy_call_handler_get_audio_local_candidate (
2172 update_candidat_widget (self, priv->audio_local_candidate_label,
2173 priv->audio_local_candidate_info_img, candidate);
2178 empathy_call_window_constructed (GObject *object)
2180 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2181 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2182 TpCallChannel *call;
2185 g_assert (priv->handler != NULL);
2187 g_object_get (priv->handler, "call-channel", &call, NULL);
2188 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2189 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2190 tp_clear_object (&call);
2192 priv->contact = empathy_call_handler_get_contact (priv->handler);
2193 g_assert (priv->contact != NULL);
2194 g_object_ref (priv->contact);
2196 if (!empathy_contact_can_voip_video (priv->contact))
2198 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2199 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2202 empathy_call_window_setup_avatars (self, priv->handler);
2203 empathy_call_window_set_state_connecting (self);
2205 if (!empathy_call_handler_has_initial_video (priv->handler))
2207 gtk_toggle_tool_button_set_active (
2208 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2210 /* If call has InitialVideo, the preview will be started once the call has
2211 * been started (start_call()). */
2213 update_send_codec (self, TRUE);
2214 update_send_codec (self, FALSE);
2215 update_recv_codec (self, TRUE);
2216 update_recv_codec (self, FALSE);
2218 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2219 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2220 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2221 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2222 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2223 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2224 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2225 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2227 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2228 G_CALLBACK (candidates_changed_cb), self, 0);
2231 static void empathy_call_window_dispose (GObject *object);
2232 static void empathy_call_window_finalize (GObject *object);
2235 empathy_call_window_set_property (GObject *object,
2236 guint property_id, const GValue *value, GParamSpec *pspec)
2238 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2240 switch (property_id)
2242 case PROP_CALL_HANDLER:
2243 priv->handler = g_value_dup_object (value);
2246 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2251 empathy_call_window_get_property (GObject *object,
2252 guint property_id, GValue *value, GParamSpec *pspec)
2254 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2256 switch (property_id)
2258 case PROP_CALL_HANDLER:
2259 g_value_set_object (value, priv->handler);
2262 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2267 empathy_call_window_class_init (
2268 EmpathyCallWindowClass *empathy_call_window_class)
2270 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2271 GParamSpec *param_spec;
2273 g_type_class_add_private (empathy_call_window_class,
2274 sizeof (EmpathyCallWindowPriv));
2276 object_class->constructed = empathy_call_window_constructed;
2277 object_class->set_property = empathy_call_window_set_property;
2278 object_class->get_property = empathy_call_window_get_property;
2280 object_class->dispose = empathy_call_window_dispose;
2281 object_class->finalize = empathy_call_window_finalize;
2283 param_spec = g_param_spec_object ("handler",
2284 "handler", "The call handler",
2285 EMPATHY_TYPE_CALL_HANDLER,
2286 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2287 g_object_class_install_property (object_class,
2288 PROP_CALL_HANDLER, param_spec);
2292 empathy_call_window_dispose (GObject *object)
2294 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2295 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2297 if (priv->dispose_has_run)
2300 priv->dispose_has_run = TRUE;
2302 if (priv->handler != NULL)
2304 empathy_call_handler_stop_call (priv->handler);
2305 tp_clear_object (&priv->handler);
2308 if (priv->bus_message_source_id != 0)
2310 g_source_remove (priv->bus_message_source_id);
2311 priv->bus_message_source_id = 0;
2314 if (priv->got_video_src > 0)
2316 g_source_remove (priv->got_video_src);
2317 priv->got_video_src = 0;
2320 if (priv->inactivity_src > 0)
2322 g_source_remove (priv->inactivity_src);
2323 priv->inactivity_src = 0;
2326 tp_clear_object (&priv->pipeline);
2327 tp_clear_object (&priv->video_input);
2328 tp_clear_object (&priv->audio_input);
2329 tp_clear_object (&priv->video_tee);
2330 tp_clear_object (&priv->ui_manager);
2331 tp_clear_object (&priv->fullscreen);
2332 tp_clear_object (&priv->camera_monitor);
2333 tp_clear_object (&priv->settings);
2334 tp_clear_object (&priv->sound_mgr);
2335 tp_clear_object (&priv->mic_menu);
2336 tp_clear_object (&priv->camera_menu);
2337 tp_clear_object (&priv->transitions);
2339 g_list_free_full (priv->notifiers, g_object_unref);
2341 if (priv->timer_id != 0)
2342 g_source_remove (priv->timer_id);
2345 tp_clear_object (&priv->contact);
2347 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2351 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2353 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2355 if (priv->video_output_motion_handler_id != 0)
2357 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2358 priv->video_output_motion_handler_id);
2359 priv->video_output_motion_handler_id = 0;
2364 empathy_call_window_finalize (GObject *object)
2366 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2367 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2369 disconnect_video_output_motion_handler (self);
2371 /* free any data held directly by the object here */
2372 g_mutex_clear (&priv->lock);
2374 g_timer_destroy (priv->timer);
2376 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2381 empathy_call_window_new (EmpathyCallHandler *handler)
2383 return EMPATHY_CALL_WINDOW (
2384 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2388 empathy_call_window_present (EmpathyCallWindow *self,
2389 EmpathyCallHandler *handler)
2391 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2393 empathy_window_present (GTK_WINDOW (self));
2395 if (self->priv->call_state == DISCONNECTED)
2397 /* start a new call if one is not already in progress */
2398 tp_clear_object (&self->priv->handler);
2399 self->priv->handler = g_object_ref (handler);
2400 empathy_call_window_connect_handler (self);
2402 empathy_call_window_restart_call (self);
2407 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2408 GstElement *conference, gpointer user_data)
2410 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2411 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2412 FsElementAddedNotifier *notifier;
2415 DEBUG ("Conference added");
2417 /* Add notifier to set the various element properties as needed */
2418 notifier = fs_element_added_notifier_new ();
2419 keyfile = fs_utils_get_default_element_properties (conference);
2421 if (keyfile != NULL)
2422 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2424 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2426 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2428 gst_bin_add (GST_BIN (priv->pipeline), conference);
2429 gst_element_set_state (conference, GST_STATE_PLAYING);
2433 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2434 GstElement *conference, gpointer user_data)
2436 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2437 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2439 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2440 gst_element_set_state (conference, GST_STATE_NULL);
2444 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2446 GstStateChangeReturn state_change_return;
2447 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2449 if (priv->pipeline == NULL)
2452 if (priv->bus_message_source_id != 0)
2454 g_source_remove (priv->bus_message_source_id);
2455 priv->bus_message_source_id = 0;
2458 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2460 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2461 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2463 if (priv->pipeline != NULL)
2464 g_object_unref (priv->pipeline);
2465 priv->pipeline = NULL;
2467 if (priv->audio_output != NULL)
2468 g_object_unref (priv->audio_output);
2469 priv->audio_output = NULL;
2470 priv->audio_output_added = FALSE;
2472 if (priv->video_tee != NULL)
2473 g_object_unref (priv->video_tee);
2474 priv->video_tee = NULL;
2476 if (priv->video_preview != NULL)
2477 clutter_actor_destroy (priv->video_preview);
2478 priv->video_preview = NULL;
2480 /* If we destroy the preview while it's being dragged, we won't
2481 * get the ::drag-end signal, so manually destroy the clone */
2482 if (priv->drag_preview != NULL)
2484 clutter_actor_destroy (priv->drag_preview);
2485 empathy_call_window_show_preview_rectangles (self, FALSE);
2486 priv->drag_preview = NULL;
2489 priv->funnel = NULL;
2491 create_pipeline (self);
2492 /* Call will be started when user will hit the 'redial' button */
2493 priv->start_call_when_playing = FALSE;
2494 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2500 g_message ("Error: could not destroy pipeline. Closing call window");
2501 gtk_widget_destroy (GTK_WIDGET (self));
2508 reset_details_pane (EmpathyCallWindow *self)
2510 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2512 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2513 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2514 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2515 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2519 empathy_call_window_disconnected (EmpathyCallWindow *self,
2522 gboolean could_disconnect = FALSE;
2523 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2524 gboolean could_reset_pipeline;
2526 /* Leave full screen mode if needed */
2527 gtk_window_unfullscreen (GTK_WINDOW (self));
2529 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2530 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2532 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2534 if (priv->call_state == CONNECTING)
2535 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2537 if (priv->call_state != REDIALING)
2538 priv->call_state = DISCONNECTED;
2540 /* Show the toolbar */
2541 clutter_state_set_state (priv->transitions, "fade-in");
2543 if (could_reset_pipeline)
2545 g_mutex_lock (&priv->lock);
2547 g_timer_stop (priv->timer);
2549 if (priv->timer_id != 0)
2550 g_source_remove (priv->timer_id);
2553 g_mutex_unlock (&priv->lock);
2556 /* We are about to destroy the window, no need to update it or create
2557 * a video preview */
2560 empathy_call_window_status_message (self, _("Disconnected"));
2562 empathy_call_window_show_hangup_button (self, FALSE);
2564 /* Unsensitive the camera and mic button */
2565 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2566 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2568 /* Be sure that the mic button is enabled */
2569 gtk_toggle_tool_button_set_active (
2570 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2572 if (priv->camera_state == CAMERA_STATE_ON)
2574 /* Restart the preview with the new pipeline. */
2575 display_video_preview (self, TRUE);
2578 /* destroy the video output; it will be recreated when we'll redial */
2579 disconnect_video_output_motion_handler (self);
2580 if (priv->video_output != NULL)
2581 clutter_actor_destroy (priv->video_output);
2582 priv->video_output = NULL;
2583 if (priv->got_video_src > 0)
2585 g_source_remove (priv->got_video_src);
2586 priv->got_video_src = 0;
2589 gtk_widget_show (priv->remote_user_avatar_widget);
2591 reset_details_pane (self);
2593 priv->sending_video = FALSE;
2594 priv->call_started = FALSE;
2596 could_disconnect = TRUE;
2598 /* TODO: display the self avatar of the preview (depends if the "Always
2599 * Show Video Preview" is enabled or not) */
2602 return could_disconnect;
2607 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2610 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2611 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2613 if (empathy_call_window_disconnected (self, TRUE) &&
2614 priv->call_state == REDIALING)
2615 empathy_call_window_restart_call (self);
2619 empathy_call_window_content_is_raw (TfContent *content)
2621 FsConference *conference;
2624 g_object_get (content, "fs-conference", &conference, NULL);
2625 g_assert (conference != NULL);
2627 /* FIXME: Ugly hack, update when moving a packetization property into
2629 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2630 gst_object_unref (conference);
2636 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2638 EmpathyCallWindow *self)
2640 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2641 FsMediaType media_type;
2643 DEBUG ("removing content");
2645 g_object_get (content, "media-type", &media_type, NULL);
2648 * This assumes that there is only one video stream per channel...
2651 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2653 if (priv->funnel != NULL)
2657 output = priv->video_output_sink;
2659 gst_element_set_state (output, GST_STATE_NULL);
2660 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2662 gst_bin_remove (GST_BIN (priv->pipeline), output);
2663 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2664 priv->funnel = NULL;
2667 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2669 if (priv->audio_output != NULL)
2671 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2673 if (priv->audio_output_added)
2674 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2675 priv->audio_output = NULL;
2676 priv->audio_output_added = FALSE;
2681 g_assert_not_reached ();
2688 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2690 EmpathyCallWindow *self)
2692 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2694 DEBUG ("Framerate changed to %u", framerate);
2696 if (priv->video_input != NULL)
2697 empathy_video_src_set_framerate (priv->video_input, framerate);
2701 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2704 EmpathyCallWindow *self)
2706 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2708 DEBUG ("Resolution changed to %ux%u", width, height);
2710 if (priv->video_input != NULL)
2712 empathy_video_src_set_resolution (priv->video_input, width, height);
2716 /* Called with global lock held */
2718 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2720 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2724 if (priv->funnel == NULL)
2726 output = priv->video_output_sink;
2728 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2732 g_warning ("Could not create fsfunnel");
2736 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2738 gst_object_unref (priv->funnel);
2739 priv->funnel = NULL;
2740 g_warning ("Could not add funnel to pipeline");
2744 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2746 g_warning ("Could not add the video output widget to the pipeline");
2750 if (!gst_element_link (priv->funnel, output))
2752 g_warning ("Could not link output sink to funnel");
2753 goto error_output_added;
2756 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2758 g_warning ("Could not start video sink");
2759 goto error_output_added;
2762 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2764 g_warning ("Could not start funnel");
2765 goto error_output_added;
2769 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2772 g_warning ("Could not get request pad from funnel");
2779 gst_element_set_locked_state (priv->funnel, TRUE);
2780 gst_element_set_locked_state (output, TRUE);
2782 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2783 gst_element_set_state (output, GST_STATE_NULL);
2785 gst_bin_remove (GST_BIN (priv->pipeline), output);
2786 gst_element_set_locked_state (output, FALSE);
2790 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2791 priv->funnel = NULL;
2796 /* Called with global lock held */
2798 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2801 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2803 GstPadTemplate *template;
2805 if (!priv->audio_output_added)
2807 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2809 g_warning ("Could not add audio sink to pipeline");
2810 g_object_unref (priv->audio_output);
2811 goto error_add_output;
2814 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2816 g_warning ("Could not start audio sink");
2821 template = gst_element_class_get_pad_template (
2822 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2824 pad = gst_element_request_pad (priv->audio_output,
2825 template, NULL, NULL);
2829 g_warning ("Could not get sink pad from sink");
2836 gst_element_set_locked_state (priv->audio_output, TRUE);
2837 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2838 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2839 priv->audio_output = NULL;
2847 empathy_call_window_update_timer (gpointer user_data)
2849 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2850 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2851 const gchar *status;
2855 time_ = g_timer_elapsed (priv->timer, NULL);
2857 if (priv->call_state == HELD)
2858 status = _("On hold");
2859 else if (!gtk_toggle_tool_button_get_active (
2860 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2863 status = _("Duration");
2865 /* Translators: 'status - minutes:seconds' the caller has been connected */
2866 str = g_strdup_printf (_("%s — %d:%02dm"),
2868 (int) time_ / 60, (int) time_ % 60);
2869 empathy_call_window_status_message (self, str);
2877 EMP_RESPONSE_BALANCE
2881 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2885 switch (response_id)
2887 case GTK_RESPONSE_CLOSE:
2888 gtk_widget_destroy (GTK_WIDGET (info_bar));
2890 case EMP_RESPONSE_BALANCE:
2891 empathy_url_show (GTK_WIDGET (info_bar),
2892 g_object_get_data (G_OBJECT (info_bar), "uri"));
2898 display_error (EmpathyCallWindow *self,
2902 const gchar *details,
2903 const gchar *button_text,
2905 gint button_response)
2907 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2908 GtkWidget *info_bar;
2909 GtkWidget *content_area;
2916 /* Create info bar */
2917 info_bar = gtk_info_bar_new ();
2919 if (button_text != NULL)
2921 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2922 button_text, button_response);
2923 g_object_set_data_full (G_OBJECT (info_bar),
2924 "uri", g_strdup (uri), g_free);
2927 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2928 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
2930 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2932 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2934 /* hbox containing the image and the messages vbox */
2935 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2936 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2939 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2940 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2942 /* vbox containing the main message and the details expander */
2943 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2944 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2947 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2949 label = gtk_label_new (NULL);
2950 gtk_label_set_markup (GTK_LABEL (label), txt);
2951 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2952 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2955 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2958 if (details != NULL)
2960 GtkWidget *expander;
2962 expander = gtk_expander_new (_("Technical Details"));
2964 txt = g_strdup_printf ("<i>%s</i>", details);
2966 label = gtk_label_new (NULL);
2967 gtk_label_set_markup (GTK_LABEL (label), txt);
2968 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2969 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2972 gtk_container_add (GTK_CONTAINER (expander), label);
2973 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2976 g_signal_connect (info_bar, "response",
2977 G_CALLBACK (on_error_infobar_response_cb), NULL);
2979 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2980 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2981 gtk_widget_show_all (info_bar);
2986 media_stream_error_to_txt (EmpathyCallWindow *self,
2987 TpCallChannel *call,
2989 TpMediaStreamError error)
2991 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2992 const gchar *cm = NULL;
2998 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3000 return g_strdup_printf (
3001 _("%s's software does not understand any of the audio formats "
3002 "supported by your computer"),
3003 empathy_contact_get_alias (priv->contact));
3005 return g_strdup_printf (
3006 _("%s's software does not understand any of the video formats "
3007 "supported by your computer"),
3008 empathy_contact_get_alias (priv->contact));
3010 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3011 return g_strdup_printf (
3012 _("Can't establish a connection to %s. "
3013 "One of you might be on a network that does not allow "
3014 "direct connections."),
3015 empathy_contact_get_alias (priv->contact));
3017 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3018 return g_strdup (_("There was a failure on the network"));
3020 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3022 return g_strdup (_("The audio formats necessary for this call "
3023 "are not installed on your computer"));
3025 return g_strdup (_("The video formats necessary for this call "
3026 "are not installed on your computer"));
3028 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3029 tp_connection_parse_object_path (
3030 tp_channel_borrow_connection (TP_CHANNEL (call)),
3033 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3034 "product=Telepathy&component=%s", cm);
3036 result = g_strdup_printf (
3037 _("Something unexpected happened in a Telepathy component. "
3038 "Please <a href=\"%s\">report this bug</a> and attach "
3039 "logs gathered from the 'Debug' window in the Help menu."), url);
3045 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3046 return g_strdup (_("There was a failure in the call engine"));
3048 case TP_MEDIA_STREAM_ERROR_EOS:
3049 return g_strdup (_("The end of the stream was reached"));
3051 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3058 empathy_call_window_stream_error (EmpathyCallWindow *self,
3059 TpCallChannel *call,
3068 desc = media_stream_error_to_txt (self, call, audio, code);
3071 /* No description, use the error message. That's not great as it's not
3072 * localized but it's better than nothing. */
3073 display_error (self, call, icon, title, msg, NULL);
3077 display_error (self, call, icon, title, desc, msg);
3083 empathy_call_window_audio_stream_error (TpCallChannel *call,
3086 EmpathyCallWindow *self)
3088 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3089 "gnome-stock-mic", _("Can't establish audio stream"));
3093 empathy_call_window_video_stream_error (TpCallChannel *call,
3096 EmpathyCallWindow *self)
3098 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3099 "camera-web", _("Can't establish video stream"));
3104 show_balance_error (EmpathyCallWindow *self)
3108 gchar *balance, *tmp;
3109 const gchar *uri, *currency;
3113 g_object_get (self->priv->handler,
3114 "call-channel", &call,
3117 conn = tp_channel_borrow_connection (call);
3118 g_object_unref (call);
3120 uri = tp_connection_get_balance_uri (conn);
3122 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3124 /* unknown balance */
3125 balance = g_strdup ("(--)");
3129 char *money = empathy_format_currency (amount, scale, currency);
3131 balance = g_strdup_printf ("%s %s",
3136 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3138 display_error (self,
3140 _("Sorry, you don’t have enough credit for that call."),
3144 EMP_RESPONSE_BALANCE);
3151 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3154 EmpathyCallWindow *self)
3156 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3157 TpCallChannel *call;
3158 gboolean can_send_video;
3160 if (state == TP_CALL_STATE_ENDED)
3162 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3163 empathy_call_window_disconnected (self, TRUE);
3164 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3165 show_balance_error (self);
3169 if (state != TP_CALL_STATE_ACCEPTED)
3172 if (priv->call_state == CONNECTED)
3175 g_timer_start (priv->timer);
3176 priv->call_state = CONNECTED;
3178 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3180 can_send_video = priv->video_input != NULL &&
3181 empathy_contact_can_voip_video (priv->contact) &&
3182 empathy_camera_monitor_get_available (priv->camera_monitor);
3184 g_object_get (priv->handler, "call-channel", &call, NULL);
3186 if (tp_call_channel_has_dtmf (call))
3187 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3189 if (priv->video_input == NULL)
3190 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3192 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3194 empathy_call_window_show_hangup_button (self, TRUE);
3196 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3198 clutter_actor_hide (priv->video_output);
3199 gtk_widget_show (priv->remote_user_avatar_widget);
3201 g_object_unref (call);
3203 g_mutex_lock (&priv->lock);
3205 priv->timer_id = g_timeout_add_seconds (1,
3206 empathy_call_window_update_timer, self);
3208 g_mutex_unlock (&priv->lock);
3210 empathy_call_window_update_timer (self);
3212 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3216 empathy_call_window_show_video_output_cb (gpointer user_data)
3218 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3220 if (self->priv->video_output != NULL)
3222 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3223 clutter_actor_show (self->priv->video_output);
3224 clutter_actor_raise_top (self->priv->overlay_box);
3231 empathy_call_window_check_video_cb (gpointer data)
3233 EmpathyCallWindow *self = data;
3235 if (self->priv->got_video)
3237 self->priv->got_video = FALSE;
3241 /* No video in the last N seconds, display the remote avatar */
3242 empathy_call_window_show_video_output (self, FALSE);
3247 /* Called from the streaming thread */
3249 empathy_call_window_video_probe_cb (GstPad *pad,
3250 GstMiniObject *mini_obj,
3251 EmpathyCallWindow *self)
3254 if (GST_IS_EVENT (mini_obj))
3257 if (G_UNLIKELY (!self->priv->got_video))
3259 /* show the remote video */
3260 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3261 empathy_call_window_show_video_output_cb,
3262 g_object_ref (self), g_object_unref);
3264 self->priv->got_video = TRUE;
3270 /* Called from the streaming thread */
3272 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3273 TfContent *content, GstPad *src, gpointer user_data)
3275 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3276 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3277 gboolean retval = FALSE;
3282 g_mutex_lock (&priv->lock);
3284 g_object_get (content, "media-type", &media_type, NULL);
3288 case TP_MEDIA_STREAM_TYPE_AUDIO:
3289 pad = empathy_call_window_get_audio_sink_pad (self, content);
3291 case TP_MEDIA_STREAM_TYPE_VIDEO:
3292 g_idle_add (empathy_call_window_show_video_output_cb, self);
3293 pad = empathy_call_window_get_video_sink_pad (self);
3295 gst_pad_add_data_probe (src,
3296 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3297 if (priv->got_video_src > 0)
3298 g_source_remove (priv->got_video_src);
3299 priv->got_video_src = g_timeout_add_seconds (1,
3300 empathy_call_window_check_video_cb, self);
3303 g_assert_not_reached ();
3309 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3310 g_warning ("Could not link %s sink pad",
3311 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3315 gst_object_unref (pad);
3319 /* If no sink could be linked, try to add fakesink to prevent the whole call
3324 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3326 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3328 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3329 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3330 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3332 gst_element_set_locked_state (fakesink, TRUE);
3333 gst_element_set_state (fakesink, GST_STATE_NULL);
3334 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3338 DEBUG ("Could not link real sink, linked fakesink instead");
3340 gst_object_unref (sinkpad);
3344 gst_object_unref (fakesink);
3349 g_mutex_unlock (&priv->lock);
3355 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3358 EmpathyCallWindowPriv *priv = self->priv;
3360 g_assert (priv->audio_output_added == FALSE);
3361 g_assert (priv->audio_output == FALSE);
3363 priv->audio_output = empathy_audio_sink_new ();
3364 g_object_ref_sink (priv->audio_output);
3366 /* volume button to output volume linking */
3367 g_object_bind_property (priv->audio_output, "volume",
3368 priv->volume_button, "value",
3369 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3371 g_object_bind_property_full (content, "requested-output-volume",
3372 priv->audio_output, "volume",
3374 audio_control_volume_to_element,
3375 element_volume_to_audio_control,
3378 /* Link volumes together, sync the current audio input volume property
3379 * back to farstream first */
3380 g_object_bind_property_full (priv->audio_output, "volume",
3381 content, "reported-output-volume",
3382 G_BINDING_SYNC_CREATE,
3383 element_volume_to_audio_control,
3384 audio_control_volume_to_element,
3387 /* For raw audio conferences assume that the producer of the raw data
3388 * has already processed it, so turn off any echo cancellation and any
3389 * other audio improvements that come with it */
3390 empathy_audio_sink_set_echo_cancel (
3391 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3392 !empathy_call_window_content_is_raw (content));
3397 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3398 TfContent *content, gpointer user_data)
3400 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3401 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3403 FsMediaType media_type;
3404 gboolean retval = FALSE;
3406 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3407 g_assert (sink != NULL);
3411 case FS_MEDIA_TYPE_AUDIO:
3413 /* For raw audio conferences assume that the receiver of the raw data
3414 * wants it unprocessed, so turn off any echo cancellation and any
3415 * other audio improvements that come with it */
3416 empathy_audio_src_set_echo_cancel (
3417 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3418 !empathy_call_window_content_is_raw (content));
3420 /* Link volumes together, sync the current audio input volume property
3421 * back to farstream first */
3422 g_object_bind_property_full (content, "requested-input-volume",
3423 priv->audio_input, "volume",
3425 audio_control_volume_to_element,
3426 element_volume_to_audio_control,
3429 g_object_bind_property_full (priv->audio_input, "volume",
3430 content, "reported-input-volume",
3431 G_BINDING_SYNC_CREATE,
3432 element_volume_to_audio_control,
3433 audio_control_volume_to_element,
3436 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3438 g_warning ("Could not add audio source to pipeline");
3442 pad = gst_element_get_static_pad (priv->audio_input, "src");
3445 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3446 g_warning ("Could not get source pad from audio source");
3450 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3452 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3453 gst_object_unref (pad);
3454 g_warning ("Could not link audio source to farsight");
3457 gst_object_unref (pad);
3459 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3461 g_warning ("Could not start audio source");
3462 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3463 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3467 /* Prepare our audio output, not added yet though */
3468 empathy_call_window_prepare_audio_output (self, content);
3472 case FS_MEDIA_TYPE_VIDEO:
3473 if (priv->video_tee != NULL)
3475 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3476 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3478 g_warning ("Could not link video source input pipeline");
3481 gst_object_unref (pad);
3487 g_assert_not_reached ();
3490 gst_object_unref (sink);
3495 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3497 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3498 GstElement *preview;
3500 disable_camera (self);
3502 DEBUG ("remove video input");
3503 preview = priv->video_preview_sink;
3505 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3506 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3507 gst_element_set_state (preview, GST_STATE_NULL);
3509 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3512 g_object_unref (priv->video_input);
3513 priv->video_input = NULL;
3514 g_object_unref (priv->video_tee);
3515 priv->video_tee = NULL;
3516 clutter_actor_destroy (priv->video_preview);
3517 priv->video_preview = NULL;
3519 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3523 start_call (EmpathyCallWindow *self)
3525 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3527 priv->call_started = TRUE;
3528 empathy_call_handler_start_call (priv->handler,
3529 gtk_get_current_event_time ());
3531 if (empathy_call_handler_has_initial_video (priv->handler))
3533 TpCallChannel *call;
3536 g_object_get (priv->handler, "call-channel", &call, NULL);
3537 /* If the call channel isn't set yet we're requesting it, if we're
3538 * requesting it with initial video it should be PENDING_SEND when we get
3541 s = TP_SENDING_STATE_PENDING_SEND;
3543 s = empathy_call_channel_get_video_state (call);
3545 if (s == TP_SENDING_STATE_PENDING_SEND ||
3546 s == TP_SENDING_STATE_SENDING)
3548 /* Enable 'send video' buttons and display the preview */
3549 gtk_toggle_tool_button_set_active (
3550 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3554 gtk_toggle_tool_button_set_active (
3555 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3557 if (priv->video_preview == NULL)
3559 create_video_preview (self);
3560 add_video_preview_to_pipeline (self);
3565 g_object_unref (call);
3570 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3573 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3574 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3575 GstState newstate, pending;
3577 empathy_call_handler_bus_message (priv->handler, bus, message);
3579 switch (GST_MESSAGE_TYPE (message))
3581 case GST_MESSAGE_STATE_CHANGED:
3582 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3584 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3586 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3587 !priv->call_started)
3589 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3590 if (newstate == GST_STATE_PAUSED)
3592 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3593 priv->pipeline_playing = TRUE;
3595 if (priv->start_call_when_playing)
3599 if (priv->video_preview_sink != NULL &&
3600 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3602 gst_message_parse_state_changed (message, NULL, &newstate,
3605 if (newstate == GST_STATE_PLAYING &&
3606 pending == GST_STATE_VOID_PENDING)
3607 empathy_call_window_stop_camera_spinning (self);
3610 case GST_MESSAGE_ERROR:
3612 GError *error = NULL;
3613 GstElement *gst_error;
3617 gst_message_parse_error (message, &error, &debug);
3618 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3620 g_message ("Element error: %s -- %s\n", error->message, debug);
3622 name = gst_element_get_name (gst_error);
3623 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3625 /* Remove the video input and continue */
3626 if (priv->video_input != NULL)
3627 empathy_call_window_remove_video_input (self);
3628 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3632 empathy_call_window_disconnected (self, TRUE);
3635 g_error_free (error);
3638 case GST_MESSAGE_UNKNOWN:
3639 case GST_MESSAGE_EOS:
3640 case GST_MESSAGE_WARNING:
3641 case GST_MESSAGE_INFO:
3642 case GST_MESSAGE_TAG:
3643 case GST_MESSAGE_BUFFERING:
3644 case GST_MESSAGE_STATE_DIRTY:
3645 case GST_MESSAGE_STEP_DONE:
3646 case GST_MESSAGE_CLOCK_PROVIDE:
3647 case GST_MESSAGE_CLOCK_LOST:
3648 case GST_MESSAGE_NEW_CLOCK:
3649 case GST_MESSAGE_STRUCTURE_CHANGE:
3650 case GST_MESSAGE_STREAM_STATUS:
3651 case GST_MESSAGE_APPLICATION:
3652 case GST_MESSAGE_ELEMENT:
3653 case GST_MESSAGE_SEGMENT_START:
3654 case GST_MESSAGE_SEGMENT_DONE:
3655 case GST_MESSAGE_DURATION:
3656 case GST_MESSAGE_ANY:
3665 empathy_call_window_members_changed_cb (TpCallChannel *call,
3666 GHashTable *updates,
3668 TpCallStateReason *reason,
3669 EmpathyCallWindow *self)
3671 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3672 GHashTableIter iter;
3673 gpointer key, value;
3674 gboolean held = FALSE;
3676 g_hash_table_iter_init (&iter, updates);
3677 while (g_hash_table_iter_next (&iter, &key, &value))
3679 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3681 /* This assumes this is a 1-1 call, otherwise one participant
3682 * putting the call on hold wouldn't mean the call is on hold
3690 priv->call_state = HELD;
3691 else if (priv->call_state == HELD)
3692 priv->call_state = CONNECTED;
3696 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3698 EmpathyCallWindow *self)
3700 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3701 TpCallChannel *call;
3703 g_object_get (priv->handler, "call-channel", &call, NULL);
3708 tp_g_signal_connect_object (call, "audio-stream-error",
3709 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3710 tp_g_signal_connect_object (call, "video-stream-error",
3711 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3714 tp_g_signal_connect_object (call, "members-changed",
3715 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3717 g_object_unref (call);
3721 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3723 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3724 TpCallChannel *call;
3726 g_signal_connect (priv->handler, "state-changed",
3727 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3728 g_signal_connect (priv->handler, "conference-added",
3729 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3730 g_signal_connect (priv->handler, "conference-removed",
3731 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3732 g_signal_connect (priv->handler, "closed",
3733 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3734 g_signal_connect (priv->handler, "src-pad-added",
3735 G_CALLBACK (empathy_call_window_src_added_cb), self);
3736 g_signal_connect (priv->handler, "content-added",
3737 G_CALLBACK (empathy_call_window_content_added_cb), self);
3738 g_signal_connect (priv->handler, "content-removed",
3739 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3741 /* We connect to ::call-channel unconditionally since we'll
3742 * get new channels if we hangup and redial or if we reuse the
3744 g_signal_connect (priv->handler, "notify::call-channel",
3745 G_CALLBACK (call_handler_notify_call_cb), self);
3747 g_signal_connect (priv->handler, "framerate-changed",
3748 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3749 g_signal_connect (priv->handler, "resolution-changed",
3750 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3752 g_object_get (priv->handler, "call-channel", &call, NULL);
3755 /* We won't get notify::call-channel for this channel, so
3756 * directly call the callback. */
3757 call_handler_notify_call_cb (priv->handler, NULL, self);
3758 g_object_unref (call);
3763 empathy_call_window_realized_cb (GtkWidget *widget,
3764 EmpathyCallWindow *self)
3768 /* Make the hangup button twice as wide */
3769 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3770 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3772 empathy_call_window_connect_handler (self);
3774 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3778 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3779 EmpathyCallWindow *window)
3781 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3783 if (priv->pipeline != NULL)
3785 if (priv->bus_message_source_id != 0)
3787 g_source_remove (priv->bus_message_source_id);
3788 priv->bus_message_source_id = 0;
3791 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3794 if (priv->call_state == CONNECTING)
3795 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3801 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3804 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3806 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3811 gtk_widget_hide (priv->dtmf_panel);
3812 gtk_widget_hide (menu);
3813 gtk_widget_hide (priv->toolbar);
3817 if (priv->dialpad_was_visible_before_fs)
3818 gtk_widget_show (priv->dtmf_panel);
3820 gtk_widget_show (menu);
3821 gtk_widget_show (priv->toolbar);
3823 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3824 priv->original_height_before_fs);
3829 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3831 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3833 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3834 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3835 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3836 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3838 if (priv->video_output != NULL)
3841 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3842 priv->video_output, TRUE, TRUE,
3843 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3850 empathy_call_window_state_event_cb (GtkWidget *widget,
3851 GdkEventWindowState *event, EmpathyCallWindow *window)
3853 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3855 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3856 gboolean set_fullscreen = event->new_window_state &
3857 GDK_WINDOW_STATE_FULLSCREEN;
3861 gboolean dialpad_was_visible;
3862 GtkAllocation allocation;
3863 gint original_width, original_height;
3865 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3866 original_width = allocation.width;
3867 original_height = allocation.height;
3869 g_object_get (priv->dtmf_panel,
3870 "visible", &dialpad_was_visible,
3873 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3874 priv->original_width_before_fs = original_width;
3875 priv->original_height_before_fs = original_height;
3877 if (priv->video_output_motion_handler_id == 0 &&
3878 priv->video_output != NULL)
3880 priv->video_output_motion_handler_id = g_signal_connect (
3881 G_OBJECT (priv->video_container), "motion-notify-event",
3882 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3888 disconnect_video_output_motion_handler (window);
3891 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3893 show_controls (window, set_fullscreen);
3894 show_borders (window, set_fullscreen);
3895 gtk_action_set_stock_id (priv->menu_fullscreen,
3896 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3897 priv->is_fullscreen = set_fullscreen;
3904 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3907 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3908 int w, h, dialpad_width;
3909 GtkAllocation allocation;
3911 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3912 w = allocation.width;
3913 h = allocation.height;
3915 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3919 gtk_widget_show (priv->dtmf_panel);
3925 gtk_widget_hide (priv->dtmf_panel);
3929 gtk_window_resize (GTK_WINDOW (window), w, h);
3933 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3936 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3937 TpCallChannel *call;
3939 priv->sending_video = (state == CAMERA_STATE_ON);
3941 if (state == CAMERA_STATE_ON)
3943 /* When we start sending video, we want to show the video preview by
3945 display_video_preview (window, TRUE);
3949 display_video_preview (window, FALSE);
3952 if (priv->call_state != CONNECTED)
3955 g_object_get (priv->handler, "call-channel", &call, NULL);
3956 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3957 empathy_call_channel_send_video (call, priv->sending_video);
3958 g_object_unref (call);
3962 empathy_call_window_hangup_cb (gpointer object,
3963 EmpathyCallWindow *self)
3965 /* stopping the call will put it the ENDED state and
3966 * from state_changed_cb we'll reconfigure the window
3968 empathy_call_handler_stop_call (self->priv->handler);
3972 empathy_call_window_restart_call (EmpathyCallWindow *window)
3974 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3976 /* Remove error info bars */
3977 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3978 (GtkCallback) gtk_widget_destroy, NULL);
3980 create_video_output_widget (window);
3981 priv->outgoing = TRUE;
3982 empathy_call_window_set_state_connecting (window);
3984 if (priv->pipeline_playing)
3985 start_call (window);
3987 /* call will be started when the pipeline is ready */
3988 priv->start_call_when_playing = TRUE;
3990 empathy_call_window_setup_avatars (window, priv->handler);
3992 empathy_call_window_show_hangup_button (window, TRUE);
3996 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3997 EmpathyCallWindow *window)
4001 active = gtk_toggle_tool_button_get_active (button);
4003 empathy_call_window_show_dialpad (window, active);
4007 empathy_call_window_fullscreen_cb (gpointer object,
4008 EmpathyCallWindow *window)
4010 empathy_call_window_fullscreen_toggle (window);
4014 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4016 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4018 if (priv->is_fullscreen)
4019 gtk_window_unfullscreen (GTK_WINDOW (window));
4021 gtk_window_fullscreen (GTK_WINDOW (window));
4025 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4026 GdkEventButton *event, EmpathyCallWindow *window)
4028 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4030 empathy_call_window_video_menu_popup (window, event->button);
4038 empathy_call_window_key_press_cb (GtkWidget *video_output,
4039 GdkEventKey *event, EmpathyCallWindow *window)
4041 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4043 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4045 /* Since we are in fullscreen mode, toggling will bring us back to
4047 empathy_call_window_fullscreen_toggle (window);
4055 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4056 GdkEventMotion *event, EmpathyCallWindow *window)
4058 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4060 if (priv->is_fullscreen)
4062 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4064 /* Show the bottom toolbar */
4065 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4072 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4076 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4078 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4080 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4081 button, gtk_get_current_event_time ());
4082 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4086 empathy_call_window_status_message (EmpathyCallWindow *self,
4089 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4093 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4095 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4097 return priv->ui_manager;
4100 EmpathyGstAudioSrc *
4101 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4103 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4105 return (EmpathyGstAudioSrc *) priv->audio_input;
4108 EmpathyGstVideoSrc *
4109 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4111 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4115 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4116 const gchar *device)
4118 EmpathyGstVideoSrc *video;
4121 /* Restart the camera only if it's already running */
4122 running = (self->priv->video_preview != NULL);
4123 video = empathy_call_window_get_video_src (self);
4126 empathy_call_window_play_camera (self, FALSE);
4128 empathy_video_src_change_device (video, device);
4131 empathy_call_window_play_camera (self, TRUE);