2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <gdk/gdkkeysyms.h>
31 #include <glib/gi18n.h>
33 #include <clutter/clutter.h>
34 #include <clutter-gtk/clutter-gtk.h>
35 #include <clutter-gst/clutter-gst.h>
37 #include <telepathy-glib/util.h>
38 #include <telepathy-farstream/telepathy-farstream.h>
39 #include <telepathy-glib/util.h>
41 #include <farstream/fs-element-added-notifier.h>
42 #include <farstream/fs-utils.h>
44 #include <libempathy/empathy-camera-monitor.h>
45 #include <libempathy/empathy-gsettings.h>
46 #include <libempathy/empathy-tp-contact-factory.h>
47 #include <libempathy/empathy-request-util.h>
48 #include <libempathy/empathy-utils.h>
50 #include <libempathy-gtk/empathy-avatar-image.h>
51 #include <libempathy-gtk/empathy-dialpad-widget.h>
52 #include <libempathy-gtk/empathy-ui-utils.h>
53 #include <libempathy-gtk/empathy-sound-manager.h>
54 #include <libempathy-gtk/empathy-geometry.h>
55 #include <libempathy-gtk/empathy-images.h>
56 #include <libempathy-gtk/empathy-call-utils.h>
58 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
59 #include <libempathy/empathy-debug.h>
61 #include "empathy-call-window.h"
62 #include "empathy-call-window-fullscreen.h"
63 #include "empathy-call-factory.h"
64 #include "empathy-video-widget.h"
65 #include "empathy-about-dialog.h"
66 #include "empathy-audio-src.h"
67 #include "empathy-audio-sink.h"
68 #include "empathy-video-src.h"
69 #include "empathy-mic-menu.h"
70 #include "empathy-preferences.h"
71 #include "empathy-rounded-actor.h"
72 #include "empathy-rounded-rectangle.h"
73 #include "empathy-rounded-texture.h"
74 #include "empathy-camera-menu.h"
76 #define CONTENT_HBOX_BORDER_WIDTH 6
77 #define CONTENT_HBOX_SPACING 3
78 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
80 #define SELF_VIDEO_SECTION_WIDTH 120
81 #define SELF_VIDEO_SECTION_HEIGHT 90
82 #define SELF_VIDEO_SECTION_MARGIN 2
83 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
85 #define FLOATING_TOOLBAR_OPACITY 192
86 #define FLOATING_TOOLBAR_WIDTH 280
87 #define FLOATING_TOOLBAR_HEIGHT 36
88 #define FLOATING_TOOLBAR_SPACING 20
90 /* The avatar's default width and height are set to the same value because we
91 want a square icon. */
92 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
93 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
94 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
96 #define SMALL_TOOLBAR_SIZE 36
98 /* If an video input error occurs, the error message will start with "v4l" */
99 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
101 /* The time interval in milliseconds between 2 outgoing rings */
102 #define MS_BETWEEN_RING 500
104 /* The roundedness of preview box and placeholders */
105 #define PREVIEW_ROUND_FACTOR 16
107 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
110 PROP_CALL_HANDLER = 1,
114 RINGING, /* Incoming call */
115 CONNECTING, /* Outgoing call */
116 CONNECTED, /* Connected */
117 HELD, /* Connected, but on hold */
118 DISCONNECTED, /* Disconnected */
119 REDIALING /* Redialing (special case of CONNECTING) */
123 CAMERA_STATE_OFF = 0,
129 PREVIEW_POS_TOP_LEFT,
130 PREVIEW_POS_TOP_RIGHT,
131 PREVIEW_POS_BOTTOM_LEFT,
132 PREVIEW_POS_BOTTOM_RIGHT,
135 struct _EmpathyCallWindowPriv
137 gboolean dispose_has_run;
138 EmpathyCallHandler *handler;
140 EmpathyContact *contact;
142 EmpathyCameraMonitor *camera_monitor;
147 GtkUIManager *ui_manager;
148 GtkWidget *errors_vbox;
149 /* widget displays the video received from the remote user. This widget is
150 * alive only during call. */
151 ClutterActor *video_output;
152 ClutterActor *video_preview;
153 ClutterActor *drag_preview;
154 ClutterActor *preview_shown_button;
155 ClutterActor *preview_hidden_button;
156 ClutterActor *preview_rectangle1;
157 ClutterActor *preview_rectangle2;
158 ClutterActor *preview_rectangle3;
159 ClutterActor *preview_rectangle4;
160 ClutterActor *preview_rectangle_box1;
161 ClutterActor *preview_rectangle_box2;
162 ClutterActor *preview_rectangle_box3;
163 ClutterActor *preview_rectangle_box4;
164 ClutterActor *preview_spinner_actor;
165 GtkWidget *preview_spinner_widget;
166 GtkWidget *video_container;
167 GtkWidget *remote_user_avatar_widget;
168 GtkWidget *remote_user_avatar_toolbar;
169 GtkWidget *remote_user_name_toolbar;
170 GtkWidget *status_label;
171 GtkWidget *hangup_button;
172 GtkWidget *audio_call_button;
173 GtkWidget *video_call_button;
174 GtkWidget *mic_button;
175 GtkWidget *volume_button;
176 GtkWidget *camera_button;
177 GtkWidget *dialpad_button;
179 GtkWidget *bottom_toolbar;
180 ClutterActor *floating_toolbar;
182 GtkAction *menu_fullscreen;
183 GtkAction *menu_swap_camera;
185 ClutterState *transitions;
187 /* The main box covering all the stage, contaning remote avatar/video */
188 ClutterActor *video_box;
189 ClutterLayoutManager *video_layout;
191 /* Coordinates of the preview drag event's start. */
192 PreviewPosition preview_pos;
194 /* We keep a reference on the hbox which contains the main content so we can
195 easilly repack everything when toggling fullscreen */
196 GtkWidget *content_hbox;
198 /* These are used to accept or reject an incoming call when the status
200 GtkWidget *incoming_call_dialog;
201 TpCallChannel *pending_channel;
202 TpChannelDispatchOperation *pending_cdo;
203 TpAddDispatchOperationContext *pending_context;
205 gulong video_output_motion_handler_id;
206 guint bus_message_source_id;
208 GtkWidget *dtmf_panel;
211 GtkWidget *details_vbox;
212 GtkWidget *vcodec_encoding_label;
213 GtkWidget *acodec_encoding_label;
214 GtkWidget *vcodec_decoding_label;
215 GtkWidget *acodec_decoding_label;
217 GtkWidget *audio_remote_candidate_label;
218 GtkWidget *audio_local_candidate_label;
219 GtkWidget *video_remote_candidate_label;
220 GtkWidget *video_local_candidate_label;
221 GtkWidget *video_remote_candidate_info_img;
222 GtkWidget *video_local_candidate_info_img;
223 GtkWidget *audio_remote_candidate_info_img;
224 GtkWidget *audio_local_candidate_info_img;
226 GstElement *video_input;
227 GstElement *video_preview_sink;
228 GstElement *video_output_sink;
229 GstElement *audio_input;
230 GstElement *audio_output;
231 gboolean audio_output_added;
232 GstElement *pipeline;
233 GstElement *video_tee;
243 gboolean call_started;
244 gboolean sending_video;
245 CameraState camera_state;
247 EmpathyCallWindowFullscreen *fullscreen;
248 gboolean is_fullscreen;
253 guint inactivity_src;
255 /* Those fields represent the state of the window before it actually was in
257 gboolean dialpad_was_visible_before_fs;
258 gint original_width_before_fs;
259 gint original_height_before_fs;
261 gint x, y, w, h, dialpad_width;
264 /* TRUE if the call should be started when the pipeline is playing */
265 gboolean start_call_when_playing;
266 /* TRUE if we requested to set the pipeline in the playing state */
267 gboolean pipeline_playing;
269 EmpathySoundManager *sound_mgr;
272 EmpathyMicMenu *mic_menu;
273 EmpathyCameraMenu *camera_menu;
276 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
278 static void empathy_call_window_realized_cb (GtkWidget *widget,
279 EmpathyCallWindow *window);
281 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
282 GdkEvent *event, EmpathyCallWindow *window);
284 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
285 GdkEventWindowState *event, EmpathyCallWindow *window);
287 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
290 static void empathy_call_window_hangup_cb (gpointer object,
291 EmpathyCallWindow *window);
293 static void empathy_call_window_fullscreen_cb (gpointer object,
294 EmpathyCallWindow *window);
296 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
298 static gboolean empathy_call_window_video_button_press_cb (
299 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
301 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
302 GdkEventKey *event, EmpathyCallWindow *window);
304 static gboolean empathy_call_window_video_output_motion_notify (
305 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
307 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
310 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
312 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
313 EmpathyCallWindow *window);
315 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
317 static void empathy_call_window_status_message (EmpathyCallWindow *window,
320 static gboolean empathy_call_window_bus_message (GstBus *bus,
321 GstMessage *message, gpointer user_data);
324 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
327 gtk_widget_set_visible (self->priv->hangup_button, show);
328 gtk_widget_set_visible (self->priv->audio_call_button, !show);
329 gtk_widget_set_visible (self->priv->video_call_button, !show);
333 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
334 EmpathyCallWindow *self)
336 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
337 empathy_call_window_restart_call (self);
341 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
342 EmpathyCallWindow *self)
344 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
345 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
346 empathy_call_window_restart_call (self);
350 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
352 EmpathyCallWindow *self)
357 g_object_get (self->priv->handler, "call-channel", &call, NULL);
359 tones[0] = tp_dtmf_event_to_char (event);
361 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
363 g_object_unref (call);
367 empathy_call_window_raise_actors (EmpathyCallWindow *self)
369 clutter_actor_raise_top (self->priv->floating_toolbar);
371 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
372 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
373 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
374 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
378 empathy_call_window_show_video_output (EmpathyCallWindow *self,
381 if (self->priv->video_output != NULL)
382 g_object_set (self->priv->video_output, "visible", show, NULL);
384 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
386 empathy_call_window_raise_actors (self);
390 create_video_output_widget (EmpathyCallWindow *self)
392 EmpathyCallWindowPriv *priv = GET_PRIV (self);
394 g_assert (priv->video_output == NULL);
395 g_assert (priv->pipeline != NULL);
397 priv->video_output = clutter_texture_new ();
399 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
402 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
403 if (priv->video_output_sink == NULL)
404 g_error ("Missing cluttersink");
406 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
408 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
411 gtk_widget_add_events (priv->video_container,
412 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
413 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
414 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
418 create_video_input (EmpathyCallWindow *self)
420 EmpathyCallWindowPriv *priv = GET_PRIV (self);
422 g_assert (priv->video_input == NULL);
423 priv->video_input = empathy_video_src_new ();
424 gst_object_ref (priv->video_input);
425 gst_object_sink (priv->video_input);
429 audio_control_volume_to_element (GBinding *binding,
430 const GValue *source_value,
431 GValue *target_value,
434 /* AudioControl volume is 0-255, with -1 for unknown */
437 hv = g_value_get_int (source_value);
442 g_value_set_double (target_value, hv/255.0);
448 element_volume_to_audio_control (GBinding *binding,
449 const GValue *source_value,
450 GValue *target_value,
455 ev = g_value_get_double (source_value);
456 ev = CLAMP (ev, 0.0, 1.0);
458 g_value_set_int (target_value, ev * 255);
463 create_audio_input (EmpathyCallWindow *self)
465 EmpathyCallWindowPriv *priv = GET_PRIV (self);
467 g_assert (priv->audio_input == NULL);
468 priv->audio_input = empathy_audio_src_new ();
469 gst_object_ref (priv->audio_input);
470 gst_object_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,
632 ClutterBinAlignment x,
633 ClutterBinAlignment y)
635 ClutterLayoutManager *layout1, *layout2;
636 EmpathyRoundedRectangle *rectangle;
637 ClutterActor *box1, *box2;
639 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
640 CLUTTER_BIN_ALIGNMENT_START);
642 box1 = clutter_box_new (layout1);
646 rectangle = empathy_rounded_rectangle_new (
647 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
648 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN,
649 PREVIEW_ROUND_FACTOR);
651 clutter_actor_set_size (box1,
652 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
653 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
654 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
656 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
657 CLUTTER_BIN_ALIGNMENT_CENTER);
659 /* We have a box with the margins and the video in the middle inside
660 * a bigger box with an extra bottom margin so we're not on top of
661 * the floating toolbar. */
662 box2 = clutter_box_new (layout2);
664 clutter_actor_set_size (box2,
665 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
666 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
668 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
669 clutter_container_add_actor (CLUTTER_CONTAINER (box2), CLUTTER_ACTOR (rectangle));
671 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
674 clutter_actor_hide (CLUTTER_ACTOR (rectangle));
676 return CLUTTER_ACTOR (rectangle);
680 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
682 self->priv->preview_rectangle1 =
683 empathy_call_window_create_preview_rectangle (self,
684 &self->priv->preview_rectangle_box1,
685 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
686 self->priv->preview_rectangle2 =
687 empathy_call_window_create_preview_rectangle (self,
688 &self->priv->preview_rectangle_box2,
689 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
690 self->priv->preview_rectangle3 =
691 empathy_call_window_create_preview_rectangle (self,
692 &self->priv->preview_rectangle_box3,
693 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
694 self->priv->preview_rectangle4 =
695 empathy_call_window_create_preview_rectangle (self,
696 &self->priv->preview_rectangle_box4,
697 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
701 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
704 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
705 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
706 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
707 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
711 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
716 guint ret_x = 0, ret_y = 0;
719 if (!clutter_actor_has_allocation (self->priv->video_box))
722 clutter_actor_get_geometry (self->priv->video_box, &box);
726 case PREVIEW_POS_TOP_LEFT:
727 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
729 case PREVIEW_POS_TOP_RIGHT:
730 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
731 - SELF_VIDEO_SECTION_WIDTH;
732 ret_y = SELF_VIDEO_SECTION_MARGIN;
734 case PREVIEW_POS_BOTTOM_LEFT:
735 ret_x = SELF_VIDEO_SECTION_MARGIN;
736 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
737 - SELF_VIDEO_SECTION_HEIGHT
738 - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING;
740 case PREVIEW_POS_BOTTOM_RIGHT:
741 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
742 - SELF_VIDEO_SECTION_WIDTH;
743 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
744 - SELF_VIDEO_SECTION_HEIGHT - FLOATING_TOOLBAR_HEIGHT
745 - FLOATING_TOOLBAR_SPACING;
748 g_warn_if_reached ();
759 static PreviewPosition
760 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
765 PreviewPosition pos = PREVIEW_POS_NONE;
767 if (!clutter_actor_has_allocation (self->priv->video_box))
770 clutter_actor_get_geometry (self->priv->video_box, &box);
772 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
773 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
774 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
775 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
777 pos = PREVIEW_POS_TOP_LEFT;
779 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
780 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
781 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
782 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
784 pos = PREVIEW_POS_TOP_RIGHT;
786 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
787 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
788 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
789 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
791 pos = PREVIEW_POS_BOTTOM_LEFT;
793 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
794 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
795 box.height - 2 * SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
796 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
798 pos = PREVIEW_POS_BOTTOM_RIGHT;
804 static ClutterActor *
805 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
808 ClutterActor *rectangle;
812 case PREVIEW_POS_TOP_LEFT:
813 rectangle = self->priv->preview_rectangle1;
815 case PREVIEW_POS_TOP_RIGHT:
816 rectangle = self->priv->preview_rectangle3;
818 case PREVIEW_POS_BOTTOM_LEFT:
819 rectangle = self->priv->preview_rectangle2;
821 case PREVIEW_POS_BOTTOM_RIGHT:
822 rectangle = self->priv->preview_rectangle4;
832 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
835 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
837 DEBUG ("moving the video preview to %d", pos);
839 self->priv->preview_pos = pos;
843 case PREVIEW_POS_TOP_LEFT:
844 clutter_bin_layout_set_alignment (layout,
845 self->priv->video_preview,
846 CLUTTER_BIN_ALIGNMENT_START,
847 CLUTTER_BIN_ALIGNMENT_START);
849 case PREVIEW_POS_TOP_RIGHT:
850 clutter_bin_layout_set_alignment (layout,
851 self->priv->video_preview,
852 CLUTTER_BIN_ALIGNMENT_END,
853 CLUTTER_BIN_ALIGNMENT_START);
855 case PREVIEW_POS_BOTTOM_LEFT:
856 clutter_bin_layout_set_alignment (layout,
857 self->priv->video_preview,
858 CLUTTER_BIN_ALIGNMENT_START,
859 CLUTTER_BIN_ALIGNMENT_END);
861 case PREVIEW_POS_BOTTOM_RIGHT:
862 clutter_bin_layout_set_alignment (layout,
863 self->priv->video_preview,
864 CLUTTER_BIN_ALIGNMENT_END,
865 CLUTTER_BIN_ALIGNMENT_END);
868 g_warn_if_reached ();
871 g_settings_set_enum (self->priv->settings, "camera-position", pos);
875 _clutter_color_from_rgba (ClutterColor *color,
878 color->red = (guint8) floor (rgba->red * 255);
879 color->green = (guint8) floor (rgba->green * 255);
880 color->blue = (guint8) floor (rgba->blue * 255);
881 color->alpha = (guint8) floor (rgba->alpha * 255);
885 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
888 ClutterActor *rectangle;
889 GtkStyleContext *context;
891 ClutterColor color, highlight;
893 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
894 context = gtk_widget_get_style_context (GTK_WIDGET (self));
895 gtk_style_context_get_color (context, 0, &rgba);
897 _clutter_color_from_rgba (&color, &rgba);
898 clutter_color_shade (&color, 1.4, &highlight);
900 empathy_rounded_rectangle_set_border_width (
901 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
902 empathy_rounded_rectangle_set_border_color (
903 EMPATHY_ROUNDED_RECTANGLE (rectangle), &highlight);
907 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
908 ClutterActor *rectangle)
910 GtkStyleContext *context;
912 ClutterColor color, darker;
914 context = gtk_widget_get_style_context (GTK_WIDGET (self));
915 gtk_style_context_get_background_color (context, 0, &rgba);
917 _clutter_color_from_rgba (&color, &rgba);
918 clutter_color_shade (&color, 0.55, &darker);
920 empathy_rounded_rectangle_set_border_width (
921 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
922 empathy_rounded_rectangle_set_border_color (
923 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
927 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
929 ClutterActor *rectangle;
931 rectangle = empathy_call_window_get_preview_rectangle (self,
932 self->priv->preview_pos);
934 /* We don't want to darken the rectangle where the preview
937 if (self->priv->preview_rectangle1 != rectangle)
938 empathy_call_window_darken_preview_rectangle (self,
939 self->priv->preview_rectangle1);
941 if (self->priv->preview_rectangle2 != rectangle)
942 empathy_call_window_darken_preview_rectangle (self,
943 self->priv->preview_rectangle2);
945 if (self->priv->preview_rectangle3 != rectangle)
946 empathy_call_window_darken_preview_rectangle (self,
947 self->priv->preview_rectangle3);
949 if (self->priv->preview_rectangle4 != rectangle)
950 empathy_call_window_darken_preview_rectangle (self,
951 self->priv->preview_rectangle4);
955 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
959 ClutterModifierType modifiers,
960 EmpathyCallWindow *self)
962 ClutterActor *stage = clutter_actor_get_stage (actor);
965 self->priv->drag_preview = clutter_clone_new (actor);
967 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
968 self->priv->drag_preview);
970 clutter_actor_transform_stage_point (actor, event_x, event_y,
973 clutter_actor_set_position (self->priv->drag_preview,
974 event_x - rel_x, event_y - rel_y);
976 clutter_drag_action_set_drag_handle (action,
977 self->priv->drag_preview);
979 clutter_actor_set_opacity (actor, 0);
980 clutter_actor_hide (self->priv->preview_shown_button);
982 empathy_call_window_show_preview_rectangles (self, TRUE);
983 empathy_call_window_darken_preview_rectangles (self);
987 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
990 clutter_actor_set_opacity (actor, 255);
994 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
998 ClutterModifierType modifiers,
999 EmpathyCallWindow *self)
1001 PreviewPosition pos;
1004 /* Get the position before destroying the drag actor, otherwise the
1005 * preview_box allocation won't be valid and we won't be able to
1006 * calculate the position. */
1007 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1009 empathy_call_window_get_preview_coordinates (self,
1010 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
1013 /* Move the preview to the destination and destroy it afterwards */
1014 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
1017 "signal-swapped-after::completed",
1018 clutter_actor_destroy, self->priv->drag_preview,
1019 "signal-swapped-after::completed",
1020 clutter_actor_show, self->priv->preview_shown_button,
1021 "signal::completed",
1022 empathy_call_window_on_animation_completed_cb, actor,
1025 self->priv->drag_preview = NULL;
1027 if (pos != PREVIEW_POS_NONE)
1028 empathy_call_window_move_video_preview (self, pos);
1030 empathy_call_window_show_preview_rectangles (self, FALSE);
1034 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1035 ClutterActor *actor,
1038 EmpathyCallWindow *self)
1040 PreviewPosition pos;
1041 gfloat event_x, event_y;
1043 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1045 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1047 if (pos != PREVIEW_POS_NONE)
1048 empathy_call_window_highlight_preview_rectangle (self, pos);
1050 empathy_call_window_darken_preview_rectangles (self);
1054 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1055 ClutterCrossingEvent *event,
1056 EmpathyCallWindow *self)
1058 ClutterActor *rectangle;
1060 rectangle = empathy_call_window_get_preview_rectangle (self,
1061 self->priv->preview_pos);
1063 empathy_call_window_highlight_preview_rectangle (self,
1064 self->priv->preview_pos);
1066 clutter_actor_show (rectangle);
1072 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1073 ClutterCrossingEvent *event,
1074 EmpathyCallWindow *self)
1076 ClutterActor *rectangle;
1078 rectangle = empathy_call_window_get_preview_rectangle (self,
1079 self->priv->preview_pos);
1081 empathy_call_window_darken_preview_rectangle (self, rectangle);
1083 clutter_actor_hide (rectangle);
1089 create_video_preview (EmpathyCallWindow *self)
1091 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1092 ClutterLayoutManager *layout, *layout_center, *layout_end;
1093 ClutterActor *preview;
1096 ClutterAction *action;
1098 PreviewPosition pos;
1099 GdkRGBA transparent = { 0., 0., 0., 0. };
1102 g_assert (priv->video_preview == NULL);
1104 pos = g_settings_get_enum (priv->settings, "camera-position");
1106 preview = empathy_rounded_texture_new ();
1107 clutter_actor_set_size (preview,
1108 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1110 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1111 if (priv->video_preview_sink == NULL)
1112 g_error ("Missing cluttersink, check your clutter-gst installation");
1113 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1114 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1116 /* Add a little offset to the video preview */
1117 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1118 CLUTTER_BIN_ALIGNMENT_START);
1119 priv->video_preview = clutter_box_new (layout);
1120 clutter_actor_set_size (priv->video_preview,
1121 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1122 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1123 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1125 /* Spinner for when changing the camera device */
1126 priv->preview_spinner_widget = gtk_spinner_new ();
1127 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1129 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1130 gtk_widget_override_background_color (
1131 gtk_clutter_actor_get_widget (
1132 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor)),
1133 GTK_STATE_FLAG_NORMAL, &transparent);
1134 gtk_widget_show (priv->preview_spinner_widget);
1137 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1138 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1139 priv->preview_spinner_widget);
1140 clutter_actor_set_size (priv->preview_spinner_actor,
1141 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1142 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1143 clutter_actor_hide (priv->preview_spinner_actor);
1145 /* We have a box with the margins and the video in the middle inside
1146 * a bigger box with an extra bottom margin so we're not on top of
1147 * the floating toolbar. */
1148 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1149 CLUTTER_BIN_ALIGNMENT_CENTER);
1150 box = clutter_box_new (layout_center);
1151 clutter_actor_set_size (box,
1152 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1153 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1155 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1156 clutter_container_add_actor (CLUTTER_CONTAINER (box),
1157 priv->preview_spinner_actor);
1158 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1160 g_object_set (priv->video_preview_sink,
1165 /* Translators: this is an "Info" label. It should be as short
1167 button = gtk_button_new_with_label (_("i"));
1168 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (button);
1169 clutter_actor_set_size (b, 24, 24);
1170 bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b));
1171 gtk_widget_override_background_color (bin, GTK_STATE_FLAG_NORMAL, &transparent);
1173 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1174 CLUTTER_BIN_ALIGNMENT_END);
1175 box = clutter_box_new (layout_end);
1176 clutter_actor_set_size (box,
1177 SELF_VIDEO_SECTION_WIDTH - 4,
1178 SELF_VIDEO_SECTION_HEIGHT - 2);
1180 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1181 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1183 g_signal_connect (button, "clicked",
1184 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1187 /* Translators: this is an "Info" label. It should be as short
1189 button = gtk_button_new_with_label (_("i"));
1190 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (button);
1191 clutter_actor_set_size (b, 24, 24);
1192 gtk_widget_override_background_color (bin, GTK_STATE_FLAG_NORMAL, &transparent);
1194 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1195 priv->preview_hidden_button,
1196 CLUTTER_BIN_ALIGNMENT_START,
1197 CLUTTER_BIN_ALIGNMENT_END);
1199 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1201 clutter_actor_hide (priv->preview_hidden_button);
1203 g_signal_connect (button, "clicked",
1204 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1207 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1208 priv->video_preview,
1209 CLUTTER_BIN_ALIGNMENT_START,
1210 CLUTTER_BIN_ALIGNMENT_END);
1212 empathy_call_window_move_video_preview (self, pos);
1214 action = clutter_drag_action_new ();
1215 g_signal_connect (action, "drag-begin",
1216 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1217 g_signal_connect (action, "drag-end",
1218 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1219 g_signal_connect (action, "drag-motion",
1220 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1222 g_signal_connect (preview, "enter-event",
1223 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1224 g_signal_connect (preview, "leave-event",
1225 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1227 clutter_actor_add_action (preview, action);
1228 clutter_actor_set_reactive (preview, TRUE);
1229 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1233 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1235 clutter_actor_show (self->priv->preview_spinner_actor);
1236 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1240 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1242 clutter_actor_hide (self->priv->preview_spinner_actor);
1243 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1247 empathy_call_window_play_camera (EmpathyCallWindow *self,
1250 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1251 GstElement *preview;
1254 if (priv->video_preview == NULL)
1256 create_video_preview (self);
1257 add_video_preview_to_pipeline (self);
1262 state = GST_STATE_PLAYING;
1266 empathy_call_window_start_camera_spinning (self);
1267 state = GST_STATE_NULL;
1270 preview = priv->video_preview_sink;
1272 gst_element_set_state (preview, state);
1273 gst_element_set_state (priv->video_tee, state);
1274 gst_element_set_state (priv->video_input, state);
1278 display_video_preview (EmpathyCallWindow *self,
1281 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1283 if (priv->video_preview == NULL)
1285 create_video_preview (self);
1286 add_video_preview_to_pipeline (self);
1291 /* Display the video preview */
1292 DEBUG ("Show video preview");
1294 empathy_call_window_play_camera (self, TRUE);
1295 clutter_actor_show (priv->video_preview);
1296 clutter_actor_raise_top (priv->floating_toolbar);
1300 /* Hide the video preview */
1301 DEBUG ("Hide video preview");
1303 if (priv->video_preview != NULL)
1305 clutter_actor_hide (priv->video_preview);
1306 empathy_call_window_play_camera (self, FALSE);
1312 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1314 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1316 empathy_call_window_status_message (window, _("Connecting…"));
1317 priv->call_state = CONNECTING;
1319 /* Show the toolbar */
1320 clutter_state_set_state (priv->transitions, "fade-in");
1323 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1324 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1328 disable_camera (EmpathyCallWindow *self)
1330 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1332 if (priv->camera_state == CAMERA_STATE_OFF)
1335 DEBUG ("Disable camera");
1337 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1339 priv->camera_state = CAMERA_STATE_OFF;
1343 enable_camera (EmpathyCallWindow *self)
1345 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1347 if (priv->camera_state == CAMERA_STATE_ON)
1350 if (priv->video_input == NULL)
1352 DEBUG ("Can't enable camera, no input");
1356 DEBUG ("Enable camera");
1358 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1360 priv->camera_state = CAMERA_STATE_ON;
1364 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1365 EmpathyCallWindow *self)
1367 if (gtk_toggle_tool_button_get_active (toggle))
1368 enable_camera (self);
1370 disable_camera (self);
1374 create_pipeline (EmpathyCallWindow *self)
1376 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1379 g_assert (priv->pipeline == NULL);
1381 priv->pipeline = gst_pipeline_new (NULL);
1382 priv->pipeline_playing = FALSE;
1384 priv->video_tee = gst_element_factory_make ("tee", NULL);
1385 gst_object_ref (priv->video_tee);
1386 gst_object_sink (priv->video_tee);
1388 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1390 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1391 priv->bus_message_source_id = gst_bus_add_watch (bus,
1392 empathy_call_window_bus_message, self);
1394 g_object_unref (bus);
1398 empathy_call_window_settings_cb (GtkAction *action,
1399 EmpathyCallWindow *self)
1401 gchar *args = g_strdup_printf ("-p %s",
1402 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1404 empathy_launch_program (BIN_DIR, "empathy", args);
1410 empathy_call_window_contents_cb (GtkAction *action,
1411 EmpathyCallWindow *self)
1413 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1417 empathy_call_window_debug_cb (GtkAction *action,
1418 EmpathyCallWindow *self)
1420 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1424 empathy_call_window_about_cb (GtkAction *action,
1425 EmpathyCallWindow *self)
1427 empathy_about_dialog_new (GTK_WINDOW (self));
1431 empathy_call_window_toolbar_timeout (gpointer data)
1433 EmpathyCallWindow *self = data;
1435 /* We don't want to hide the toolbar if we're not in a call, as
1436 * to show the call status all the time. */
1437 if (self->priv->call_state != CONNECTING &&
1438 self->priv->call_state != DISCONNECTED)
1439 clutter_state_set_state (self->priv->transitions, "fade-out");
1445 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1447 EmpathyCallWindow *self)
1449 clutter_state_set_state (self->priv->transitions, "fade-in");
1451 if (self->priv->inactivity_src > 0)
1452 g_source_remove (self->priv->inactivity_src);
1454 self->priv->inactivity_src = g_timeout_add_seconds (3,
1455 empathy_call_window_toolbar_timeout, self);
1461 empathy_call_window_configure_event_cb (GtkWidget *widget,
1463 EmpathyCallWindow *self)
1465 GdkWindow *gdk_window;
1466 GdkWindowState window_state;
1468 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1469 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1471 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1472 &self->priv->dialpad_width, NULL);
1474 gdk_window = gtk_widget_get_window (widget);
1475 window_state = gdk_window_get_state (gdk_window);
1476 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1482 empathy_call_window_destroyed_cb (GtkWidget *object,
1483 EmpathyCallWindow *self)
1485 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1487 /* Save the geometry as if the dialpad was hidden. */
1488 empathy_geometry_save_values (GTK_WINDOW (self),
1489 self->priv->x, self->priv->y,
1490 self->priv->w - self->priv->dialpad_width, self->priv->h,
1491 self->priv->maximized);
1496 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1498 ClutterBindConstraint *constraint)
1500 ClutterActorBox allocation;
1502 clutter_actor_get_allocation_box (stage, &allocation);
1504 clutter_bind_constraint_set_offset (constraint,
1505 allocation.y2 - allocation.y1 -
1506 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1510 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1512 EmpathyCallWindow *self)
1514 switch (response_id)
1516 case GTK_RESPONSE_ACCEPT:
1517 tp_channel_dispatch_operation_handle_with_async (
1518 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1520 tp_clear_object (&self->priv->pending_cdo);
1521 tp_clear_object (&self->priv->pending_channel);
1522 tp_clear_object (&self->priv->pending_context);
1525 case GTK_RESPONSE_CANCEL:
1526 tp_channel_dispatch_operation_close_channels_async (
1527 self->priv->pending_cdo, NULL, NULL);
1529 empathy_call_window_status_message (self, _("Disconnected"));
1530 self->priv->call_state = DISCONNECTED;
1533 g_warn_if_reached ();
1538 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1542 g_assert (self->priv->call_state != CONNECTED);
1544 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1546 empathy_call_window_status_message (self, _("Incoming call"));
1547 self->priv->call_state = RINGING;
1549 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1550 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1551 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1552 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1553 empathy_contact_get_alias (self->priv->contact));
1555 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1556 _("Reject"), GTK_RESPONSE_CANCEL,
1557 _("Answer"), GTK_RESPONSE_ACCEPT,
1560 g_signal_connect (self->priv->incoming_call_dialog, "response",
1561 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1562 gtk_widget_show (self->priv->incoming_call_dialog);
1566 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1570 EmpathyCallWindow *self)
1572 tp_clear_object (&self->priv->pending_cdo);
1573 tp_clear_object (&self->priv->pending_channel);
1574 tp_clear_object (&self->priv->pending_context);
1576 /* We don't know if the incoming call has been accepted or not, so we
1577 * assume it hasn't and if it has, we'll set the proper status when
1578 * we get the new handler. */
1579 empathy_call_window_status_message (self, _("Disconnected"));
1580 self->priv->call_state = DISCONNECTED;
1582 gtk_widget_destroy (self->priv->incoming_call_dialog);
1583 self->priv->incoming_call_dialog = NULL;
1587 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1588 TpCallChannel *channel,
1589 TpChannelDispatchOperation *dispatch_operation,
1590 TpAddDispatchOperationContext *context)
1592 g_assert (self->priv->pending_channel == NULL);
1593 g_assert (self->priv->pending_context == NULL);
1594 g_assert (self->priv->pending_cdo == NULL);
1596 /* Start ringing and delay until the user answers or hangs. */
1597 self->priv->pending_channel = g_object_ref (channel);
1598 self->priv->pending_context = g_object_ref (context);
1599 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1601 g_signal_connect (self->priv->pending_cdo, "invalidated",
1602 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1604 empathy_call_window_set_state_ringing (self);
1605 tp_add_dispatch_operation_context_accept (context);
1609 empathy_call_window_init (EmpathyCallWindow *self)
1611 EmpathyCallWindowPriv *priv;
1613 GtkWidget *top_vbox;
1615 ClutterConstraint *constraint;
1616 ClutterActor *remote_avatar;
1617 GtkStyleContext *context;
1621 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1622 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1624 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1626 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1627 gui = empathy_builder_get_file (filename,
1628 "call_window_vbox", &top_vbox,
1629 "errors_vbox", &priv->errors_vbox,
1630 "pane", &priv->pane,
1631 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1632 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1633 "status_label", &priv->status_label,
1634 "audiocall", &priv->audio_call_button,
1635 "videocall", &priv->video_call_button,
1636 "microphone", &priv->mic_button,
1637 "volume", &priv->volume_button,
1638 "camera", &priv->camera_button,
1639 "hangup", &priv->hangup_button,
1640 "dialpad", &priv->dialpad_button,
1641 "toolbar", &priv->toolbar,
1642 "bottom_toolbar", &priv->bottom_toolbar,
1643 "ui_manager", &priv->ui_manager,
1644 "menufullscreen", &priv->menu_fullscreen,
1645 "menupreviewswap", &priv->menu_swap_camera,
1646 "details_vbox", &priv->details_vbox,
1647 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1648 "acodec_encoding_label", &priv->acodec_encoding_label,
1649 "acodec_decoding_label", &priv->acodec_decoding_label,
1650 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1651 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1652 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1653 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1654 "video_local_candidate_label", &priv->video_local_candidate_label,
1655 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1656 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1657 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1658 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1662 empathy_builder_connect (gui, self,
1663 "hangup", "clicked", empathy_call_window_hangup_cb,
1664 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1665 "videocall", "clicked", empathy_call_window_video_call_cb,
1666 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1667 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1668 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1669 "menusettings", "activate", empathy_call_window_settings_cb,
1670 "menucontents", "activate", empathy_call_window_contents_cb,
1671 "menudebug", "activate", empathy_call_window_debug_cb,
1672 "menuabout", "activate", empathy_call_window_about_cb,
1673 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1674 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1675 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1676 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1679 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1681 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1683 g_object_bind_property (priv->camera_monitor, "available",
1684 priv->camera_button, "sensitive",
1685 G_BINDING_SYNC_CREATE);
1687 g_signal_connect (priv->camera_monitor, "added",
1688 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1689 g_signal_connect (priv->camera_monitor, "removed",
1690 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1692 priv->lock = g_mutex_new ();
1694 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1696 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1697 CONTENT_HBOX_SPACING);
1698 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1699 CONTENT_HBOX_BORDER_WIDTH);
1700 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1703 /* main contents remote avatar/video box */
1704 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1705 CLUTTER_BIN_ALIGNMENT_CENTER);
1707 priv->video_box = clutter_box_new (priv->video_layout);
1709 priv->video_container = gtk_clutter_embed_new ();
1711 gtk_widget_set_size_request (priv->video_container,
1712 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1714 /* Set the background color to that of the rest of the window */
1715 context = gtk_widget_get_style_context (priv->content_hbox);
1716 gtk_style_context_get_background_color (context,
1717 GTK_STATE_FLAG_NORMAL, &rgba);
1718 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1719 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1720 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1721 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1722 clutter_stage_set_color (
1723 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1724 GTK_CLUTTER_EMBED (priv->video_container))),
1727 clutter_container_add (
1728 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1729 GTK_CLUTTER_EMBED (priv->video_container))),
1733 constraint = clutter_bind_constraint_new (
1734 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1735 CLUTTER_BIND_SIZE, 0);
1736 clutter_actor_add_constraint (priv->video_box, constraint);
1738 priv->remote_user_avatar_widget = gtk_image_new ();
1739 remote_avatar = gtk_clutter_actor_new_with_contents (
1740 priv->remote_user_avatar_widget);
1742 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1745 empathy_call_window_create_preview_rectangles (self);
1747 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1748 priv->video_container, TRUE, TRUE,
1749 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1751 create_pipeline (self);
1752 create_video_output_widget (self);
1753 create_audio_input (self);
1754 create_video_input (self);
1756 priv->floating_toolbar = empathy_rounded_actor_new (2);
1758 gtk_widget_reparent (priv->bottom_toolbar,
1759 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1761 constraint = clutter_bind_constraint_new (
1762 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1765 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1768 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1769 "notify::allocation",
1770 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1773 clutter_actor_set_size (priv->floating_toolbar,
1774 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1775 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1777 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1778 priv->floating_toolbar,
1779 CLUTTER_BIN_ALIGNMENT_CENTER,
1780 CLUTTER_BIN_ALIGNMENT_END);
1782 clutter_actor_raise_top (priv->floating_toolbar);
1784 /* Transitions for the floating toolbar */
1785 priv->transitions = clutter_state_new ();
1787 /* all transitions last for 2s */
1788 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1790 /* transition from any state to "fade-out" state */
1791 clutter_state_set (priv->transitions, NULL, "fade-out",
1792 priv->floating_toolbar,
1793 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1796 /* transition from any state to "fade-in" state */
1797 clutter_state_set (priv->transitions, NULL, "fade-in",
1798 priv->floating_toolbar,
1799 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1802 /* put the actor into the "fade-in" state with no animation */
1803 clutter_state_warp_to_state (priv->transitions, "fade-in");
1805 /* The call will be started as soon the pipeline is playing */
1806 priv->start_call_when_playing = TRUE;
1808 priv->dtmf_panel = empathy_dialpad_widget_new ();
1809 g_signal_connect (priv->dtmf_panel, "start-tone",
1810 G_CALLBACK (dtmf_start_tone_cb), self);
1812 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1815 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1818 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1820 gtk_widget_show_all (top_vbox);
1822 gtk_widget_hide (priv->dtmf_panel);
1823 gtk_widget_hide (priv->details_vbox);
1825 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1827 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1828 priv->video_container);
1830 /* We hide the bottom toolbar after 3s of inactivity and show it
1831 * again on mouse movement */
1832 priv->inactivity_src = g_timeout_add_seconds (3,
1833 empathy_call_window_toolbar_timeout, self);
1835 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1836 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1838 g_signal_connect (G_OBJECT (self), "realize",
1839 G_CALLBACK (empathy_call_window_realized_cb), self);
1841 g_signal_connect (G_OBJECT (self), "delete-event",
1842 G_CALLBACK (empathy_call_window_delete_cb), self);
1844 g_signal_connect (G_OBJECT (self), "window-state-event",
1845 G_CALLBACK (empathy_call_window_state_event_cb), self);
1847 g_signal_connect (G_OBJECT (self), "key-press-event",
1848 G_CALLBACK (empathy_call_window_key_press_cb), self);
1850 g_signal_connect (self, "motion-notify-event",
1851 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1853 priv->timer = g_timer_new ();
1855 g_object_ref (priv->ui_manager);
1856 g_object_unref (gui);
1858 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1859 priv->mic_menu = empathy_mic_menu_new (self);
1860 priv->camera_menu = empathy_camera_menu_new (self);
1862 empathy_call_window_show_hangup_button (self, TRUE);
1864 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1865 /* These signals are used to track the window position and save it
1866 * when the window is destroyed. We need to do this as we don't want
1867 * the window geometry to be saved with the dialpad taken into account. */
1868 g_signal_connect (self, "destroy",
1869 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1870 g_signal_connect (self, "configure-event",
1871 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1872 g_signal_connect (self, "window-state-event",
1873 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1875 /* Don't display labels in both toolbars */
1876 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1879 /* Instead of specifying a width and a height, we specify only one size. That's
1880 because we want a square avatar icon. */
1882 init_contact_avatar_with_size (EmpathyContact *contact,
1883 GtkWidget *image_widget,
1886 GdkPixbuf *pixbuf_avatar = NULL;
1888 if (contact != NULL)
1890 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1894 if (pixbuf_avatar == NULL)
1896 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1897 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1900 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1902 if (pixbuf_avatar != NULL)
1903 g_object_unref (pixbuf_avatar);
1907 set_window_title (EmpathyCallWindow *self)
1909 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1912 if (priv->contact != NULL)
1914 /* translators: Call is a noun and %s is the contact name. This string
1915 * is used in the window title */
1916 tmp = g_strdup_printf (_("Call with %s"),
1917 empathy_contact_get_alias (priv->contact));
1918 gtk_window_set_title (GTK_WINDOW (self), tmp);
1923 g_warning ("Unknown remote contact!");
1928 set_remote_user_name (EmpathyCallWindow *self,
1929 EmpathyContact *contact)
1931 const gchar *alias = empathy_contact_get_alias (contact);
1932 const gchar *status = empathy_contact_get_status (contact);
1935 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1936 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1942 contact_name_changed_cb (EmpathyContact *contact,
1944 EmpathyCallWindow *self)
1946 set_window_title (self);
1947 set_remote_user_name (self, contact);
1951 contact_presence_changed_cb (EmpathyContact *contact,
1953 EmpathyCallWindow *self)
1955 set_remote_user_name (self, contact);
1959 contact_avatar_changed_cb (EmpathyContact *contact,
1961 EmpathyCallWindow *self)
1964 GtkAllocation allocation;
1965 GtkWidget *avatar_widget;
1967 avatar_widget = self->priv->remote_user_avatar_widget;
1969 gtk_widget_get_allocation (avatar_widget, &allocation);
1970 size = allocation.height;
1974 /* the widget is not allocated yet, set a default size */
1975 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1976 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1979 init_contact_avatar_with_size (contact, avatar_widget, size);
1981 avatar_widget = self->priv->remote_user_avatar_toolbar;
1983 gtk_widget_get_allocation (avatar_widget, &allocation);
1984 size = allocation.height;
1988 /* the widget is not allocated yet, set a default size */
1989 size = SMALL_TOOLBAR_SIZE;
1992 init_contact_avatar_with_size (contact, avatar_widget, size);
1996 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1997 EmpathyCallHandler *handler)
1999 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2001 tp_g_signal_connect_object (priv->contact, "notify::name",
2002 G_CALLBACK (contact_name_changed_cb), self, 0);
2003 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2004 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2005 tp_g_signal_connect_object (priv->contact, "notify::presence",
2006 G_CALLBACK (contact_presence_changed_cb), self, 0);
2008 set_window_title (self);
2009 set_remote_user_name (self, priv->contact);
2011 init_contact_avatar_with_size (priv->contact,
2012 priv->remote_user_avatar_widget,
2013 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2014 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2016 init_contact_avatar_with_size (priv->contact,
2017 priv->remote_user_avatar_toolbar,
2018 SMALL_TOOLBAR_SIZE);
2020 /* The remote avatar is shown by default and will be hidden when we receive
2021 video from the remote side. */
2022 clutter_actor_hide (priv->video_output);
2023 gtk_widget_show (priv->remote_user_avatar_widget);
2027 update_send_codec (EmpathyCallWindow *self,
2030 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2037 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2038 widget = priv->acodec_encoding_label;
2042 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2043 widget = priv->vcodec_encoding_label;
2049 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2050 gtk_label_set_text (GTK_LABEL (widget), tmp);
2055 send_audio_codec_notify_cb (GObject *object,
2059 EmpathyCallWindow *self = user_data;
2061 update_send_codec (self, TRUE);
2065 send_video_codec_notify_cb (GObject *object,
2069 EmpathyCallWindow *self = user_data;
2071 update_send_codec (self, FALSE);
2075 update_recv_codec (EmpathyCallWindow *self,
2078 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2081 GString *str = NULL;
2085 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2086 widget = priv->acodec_decoding_label;
2090 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2091 widget = priv->vcodec_decoding_label;
2097 for (l = codecs; l != NULL; l = g_list_next (l))
2099 FsCodec *codec = l->data;
2102 str = g_string_new (NULL);
2104 g_string_append (str, ", ");
2106 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2110 gtk_label_set_text (GTK_LABEL (widget), str->str);
2111 g_string_free (str, TRUE);
2115 recv_audio_codecs_notify_cb (GObject *object,
2119 EmpathyCallWindow *self = user_data;
2121 update_recv_codec (self, TRUE);
2125 recv_video_codecs_notify_cb (GObject *object,
2129 EmpathyCallWindow *self = user_data;
2131 update_recv_codec (self, FALSE);
2134 static const gchar *
2135 candidate_type_to_str (FsCandidate *candidate)
2137 switch (candidate->type)
2139 case FS_CANDIDATE_TYPE_HOST:
2141 case FS_CANDIDATE_TYPE_SRFLX:
2142 return "server reflexive";
2143 case FS_CANDIDATE_TYPE_PRFLX:
2144 return "peer reflexive";
2145 case FS_CANDIDATE_TYPE_RELAY:
2147 case FS_CANDIDATE_TYPE_MULTICAST:
2154 static const gchar *
2155 candidate_type_to_desc (FsCandidate *candidate)
2157 switch (candidate->type)
2159 case FS_CANDIDATE_TYPE_HOST:
2160 return _("The IP address as seen by the machine");
2161 case FS_CANDIDATE_TYPE_SRFLX:
2162 return _("The IP address as seen by a server on the Internet");
2163 case FS_CANDIDATE_TYPE_PRFLX:
2164 return _("The IP address of the peer as seen by the other side");
2165 case FS_CANDIDATE_TYPE_RELAY:
2166 return _("The IP address of a relay server");
2167 case FS_CANDIDATE_TYPE_MULTICAST:
2168 return _("The IP address of the multicast group");
2175 update_candidat_widget (EmpathyCallWindow *self,
2178 FsCandidate *candidate)
2182 g_assert (candidate != NULL);
2183 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2184 candidate->port, candidate_type_to_str (candidate));
2186 gtk_label_set_text (GTK_LABEL (label), str);
2187 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2193 candidates_changed_cb (GObject *object,
2195 EmpathyCallWindow *self)
2197 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2198 FsCandidate *candidate = NULL;
2200 if (type == FS_MEDIA_TYPE_VIDEO)
2202 /* Update remote candidate */
2203 candidate = empathy_call_handler_get_video_remote_candidate (
2206 update_candidat_widget (self, priv->video_remote_candidate_label,
2207 priv->video_remote_candidate_info_img, candidate);
2209 /* Update local candidate */
2210 candidate = empathy_call_handler_get_video_local_candidate (
2213 update_candidat_widget (self, priv->video_local_candidate_label,
2214 priv->video_local_candidate_info_img, candidate);
2218 /* Update remote candidate */
2219 candidate = empathy_call_handler_get_audio_remote_candidate (
2222 update_candidat_widget (self, priv->audio_remote_candidate_label,
2223 priv->audio_remote_candidate_info_img, candidate);
2225 /* Update local candidate */
2226 candidate = empathy_call_handler_get_audio_local_candidate (
2229 update_candidat_widget (self, priv->audio_local_candidate_label,
2230 priv->audio_local_candidate_info_img, candidate);
2235 empathy_call_window_constructed (GObject *object)
2237 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2238 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2239 TpCallChannel *call;
2242 g_assert (priv->handler != NULL);
2244 g_object_get (priv->handler, "call-channel", &call, NULL);
2245 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2246 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2247 tp_clear_object (&call);
2249 priv->contact = empathy_call_handler_get_contact (priv->handler);
2250 g_assert (priv->contact != NULL);
2251 g_object_ref (priv->contact);
2253 if (!empathy_contact_can_voip_video (priv->contact))
2255 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2256 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2259 empathy_call_window_setup_avatars (self, priv->handler);
2260 empathy_call_window_set_state_connecting (self);
2262 if (!empathy_call_handler_has_initial_video (priv->handler))
2264 gtk_toggle_tool_button_set_active (
2265 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2267 /* If call has InitialVideo, the preview will be started once the call has
2268 * been started (start_call()). */
2270 update_send_codec (self, TRUE);
2271 update_send_codec (self, FALSE);
2272 update_recv_codec (self, TRUE);
2273 update_recv_codec (self, FALSE);
2275 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2276 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2277 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2278 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2279 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2280 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2281 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2282 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2284 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2285 G_CALLBACK (candidates_changed_cb), self, 0);
2288 static void empathy_call_window_dispose (GObject *object);
2289 static void empathy_call_window_finalize (GObject *object);
2292 empathy_call_window_set_property (GObject *object,
2293 guint property_id, const GValue *value, GParamSpec *pspec)
2295 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2297 switch (property_id)
2299 case PROP_CALL_HANDLER:
2300 priv->handler = g_value_dup_object (value);
2303 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2308 empathy_call_window_get_property (GObject *object,
2309 guint property_id, GValue *value, GParamSpec *pspec)
2311 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2313 switch (property_id)
2315 case PROP_CALL_HANDLER:
2316 g_value_set_object (value, priv->handler);
2319 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2324 empathy_call_window_class_init (
2325 EmpathyCallWindowClass *empathy_call_window_class)
2327 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2328 GParamSpec *param_spec;
2330 g_type_class_add_private (empathy_call_window_class,
2331 sizeof (EmpathyCallWindowPriv));
2333 object_class->constructed = empathy_call_window_constructed;
2334 object_class->set_property = empathy_call_window_set_property;
2335 object_class->get_property = empathy_call_window_get_property;
2337 object_class->dispose = empathy_call_window_dispose;
2338 object_class->finalize = empathy_call_window_finalize;
2340 param_spec = g_param_spec_object ("handler",
2341 "handler", "The call handler",
2342 EMPATHY_TYPE_CALL_HANDLER,
2343 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2344 g_object_class_install_property (object_class,
2345 PROP_CALL_HANDLER, param_spec);
2349 empathy_call_window_dispose (GObject *object)
2351 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2352 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2354 if (priv->dispose_has_run)
2357 priv->dispose_has_run = TRUE;
2359 if (priv->handler != NULL)
2361 empathy_call_handler_stop_call (priv->handler);
2362 tp_clear_object (&priv->handler);
2365 if (priv->bus_message_source_id != 0)
2367 g_source_remove (priv->bus_message_source_id);
2368 priv->bus_message_source_id = 0;
2371 if (priv->got_video_src > 0)
2373 g_source_remove (priv->got_video_src);
2374 priv->got_video_src = 0;
2377 if (priv->inactivity_src > 0)
2379 g_source_remove (priv->inactivity_src);
2380 priv->inactivity_src = 0;
2383 tp_clear_object (&priv->pipeline);
2384 tp_clear_object (&priv->video_input);
2385 tp_clear_object (&priv->audio_input);
2386 tp_clear_object (&priv->video_tee);
2387 tp_clear_object (&priv->ui_manager);
2388 tp_clear_object (&priv->fullscreen);
2389 tp_clear_object (&priv->camera_monitor);
2390 tp_clear_object (&priv->settings);
2391 tp_clear_object (&priv->sound_mgr);
2392 tp_clear_object (&priv->mic_menu);
2393 tp_clear_object (&priv->camera_menu);
2394 tp_clear_object (&priv->transitions);
2396 g_list_free_full (priv->notifiers, g_object_unref);
2398 if (priv->timer_id != 0)
2399 g_source_remove (priv->timer_id);
2402 tp_clear_object (&priv->contact);
2404 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2408 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2410 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2412 if (priv->video_output_motion_handler_id != 0)
2414 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2415 priv->video_output_motion_handler_id);
2416 priv->video_output_motion_handler_id = 0;
2421 empathy_call_window_finalize (GObject *object)
2423 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2424 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2426 disconnect_video_output_motion_handler (self);
2428 /* free any data held directly by the object here */
2429 g_mutex_free (priv->lock);
2431 g_timer_destroy (priv->timer);
2433 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2438 empathy_call_window_new (EmpathyCallHandler *handler)
2440 return EMPATHY_CALL_WINDOW (
2441 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2445 empathy_call_window_present (EmpathyCallWindow *self,
2446 EmpathyCallHandler *handler)
2448 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2450 empathy_window_present (GTK_WINDOW (self));
2452 if (self->priv->call_state == DISCONNECTED)
2454 /* start a new call if one is not already in progress */
2455 tp_clear_object (&self->priv->handler);
2456 self->priv->handler = g_object_ref (handler);
2457 empathy_call_window_connect_handler (self);
2459 empathy_call_window_restart_call (self);
2464 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2465 GstElement *conference, gpointer user_data)
2467 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2468 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2469 FsElementAddedNotifier *notifier;
2472 DEBUG ("Conference added");
2474 /* Add notifier to set the various element properties as needed */
2475 notifier = fs_element_added_notifier_new ();
2476 keyfile = fs_utils_get_default_element_properties (conference);
2478 if (keyfile != NULL)
2479 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2481 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2483 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2485 gst_bin_add (GST_BIN (priv->pipeline), conference);
2486 gst_element_set_state (conference, GST_STATE_PLAYING);
2490 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2491 GstElement *conference, gpointer user_data)
2493 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2494 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2496 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2497 gst_element_set_state (conference, GST_STATE_NULL);
2501 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2503 GstStateChangeReturn state_change_return;
2504 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2506 if (priv->pipeline == NULL)
2509 if (priv->bus_message_source_id != 0)
2511 g_source_remove (priv->bus_message_source_id);
2512 priv->bus_message_source_id = 0;
2515 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2517 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2518 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2520 if (priv->pipeline != NULL)
2521 g_object_unref (priv->pipeline);
2522 priv->pipeline = NULL;
2524 if (priv->audio_output != NULL)
2525 g_object_unref (priv->audio_output);
2526 priv->audio_output = NULL;
2527 priv->audio_output_added = FALSE;
2529 if (priv->video_tee != NULL)
2530 g_object_unref (priv->video_tee);
2531 priv->video_tee = NULL;
2533 if (priv->video_preview != NULL)
2534 clutter_actor_destroy (priv->video_preview);
2535 priv->video_preview = NULL;
2537 /* If we destroy the preview while it's being dragged, we won't
2538 * get the ::drag-end signal, so manually destroy the clone */
2539 if (priv->drag_preview != NULL)
2541 clutter_actor_destroy (priv->drag_preview);
2542 empathy_call_window_show_preview_rectangles (self, FALSE);
2543 priv->drag_preview = NULL;
2546 priv->funnel = NULL;
2548 create_pipeline (self);
2549 /* Call will be started when user will hit the 'redial' button */
2550 priv->start_call_when_playing = FALSE;
2551 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2557 g_message ("Error: could not destroy pipeline. Closing call window");
2558 gtk_widget_destroy (GTK_WIDGET (self));
2565 reset_details_pane (EmpathyCallWindow *self)
2567 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2569 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2570 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2571 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2572 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2576 empathy_call_window_disconnected (EmpathyCallWindow *self,
2579 gboolean could_disconnect = FALSE;
2580 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2581 gboolean could_reset_pipeline;
2583 /* Leave full screen mode if needed */
2584 gtk_window_unfullscreen (GTK_WINDOW (self));
2586 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2587 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2589 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2591 if (priv->call_state == CONNECTING)
2592 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2594 if (priv->call_state != REDIALING)
2595 priv->call_state = DISCONNECTED;
2597 /* Show the toolbar */
2598 clutter_state_set_state (priv->transitions, "fade-in");
2600 if (could_reset_pipeline)
2602 g_mutex_lock (priv->lock);
2604 g_timer_stop (priv->timer);
2606 if (priv->timer_id != 0)
2607 g_source_remove (priv->timer_id);
2610 g_mutex_unlock (priv->lock);
2613 /* We are about to destroy the window, no need to update it or create
2614 * a video preview */
2617 empathy_call_window_status_message (self, _("Disconnected"));
2619 empathy_call_window_show_hangup_button (self, FALSE);
2621 /* Unsensitive the camera and mic button */
2622 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2623 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2625 /* Be sure that the mic button is enabled */
2626 gtk_toggle_tool_button_set_active (
2627 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2629 if (priv->camera_state == CAMERA_STATE_ON)
2631 /* Restart the preview with the new pipeline. */
2632 display_video_preview (self, TRUE);
2635 /* destroy the video output; it will be recreated when we'll redial */
2636 disconnect_video_output_motion_handler (self);
2637 if (priv->video_output != NULL)
2638 clutter_actor_destroy (priv->video_output);
2639 priv->video_output = NULL;
2640 if (priv->got_video_src > 0)
2642 g_source_remove (priv->got_video_src);
2643 priv->got_video_src = 0;
2646 gtk_widget_show (priv->remote_user_avatar_widget);
2648 reset_details_pane (self);
2650 priv->sending_video = FALSE;
2651 priv->call_started = FALSE;
2653 could_disconnect = TRUE;
2655 /* TODO: display the self avatar of the preview (depends if the "Always
2656 * Show Video Preview" is enabled or not) */
2659 return could_disconnect;
2664 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2667 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2668 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2670 if (empathy_call_window_disconnected (self, TRUE) &&
2671 priv->call_state == REDIALING)
2672 empathy_call_window_restart_call (self);
2676 empathy_call_window_content_is_raw (TfContent *content)
2678 FsConference *conference;
2681 g_object_get (content, "fs-conference", &conference, NULL);
2682 g_assert (conference != NULL);
2684 /* FIXME: Ugly hack, update when moving a packetization property into
2686 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2687 gst_object_unref (conference);
2693 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2695 EmpathyCallWindow *self)
2697 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2698 FsMediaType media_type;
2700 DEBUG ("removing content");
2702 g_object_get (content, "media-type", &media_type, NULL);
2705 * This assumes that there is only one video stream per channel...
2708 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2710 if (priv->funnel != NULL)
2714 output = priv->video_output_sink;
2716 gst_element_set_state (output, GST_STATE_NULL);
2717 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2719 gst_bin_remove (GST_BIN (priv->pipeline), output);
2720 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2721 priv->funnel = NULL;
2724 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2726 if (priv->audio_output != NULL)
2728 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2730 if (priv->audio_output_added)
2731 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2732 priv->audio_output = NULL;
2733 priv->audio_output_added = FALSE;
2738 g_assert_not_reached ();
2745 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2747 EmpathyCallWindow *self)
2749 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2751 DEBUG ("Framerate changed to %u", framerate);
2753 if (priv->video_input != NULL)
2754 empathy_video_src_set_framerate (priv->video_input, framerate);
2758 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2761 EmpathyCallWindow *self)
2763 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2765 DEBUG ("Resolution changed to %ux%u", width, height);
2767 if (priv->video_input != NULL)
2769 empathy_video_src_set_resolution (priv->video_input, width, height);
2773 /* Called with global lock held */
2775 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2777 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2781 if (priv->funnel == NULL)
2783 output = priv->video_output_sink;
2785 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2789 g_warning ("Could not create fsfunnel");
2793 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2795 gst_object_unref (priv->funnel);
2796 priv->funnel = NULL;
2797 g_warning ("Could not add funnel to pipeline");
2801 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2803 g_warning ("Could not add the video output widget to the pipeline");
2807 if (!gst_element_link (priv->funnel, output))
2809 g_warning ("Could not link output sink to funnel");
2810 goto error_output_added;
2813 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2815 g_warning ("Could not start video sink");
2816 goto error_output_added;
2819 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2821 g_warning ("Could not start funnel");
2822 goto error_output_added;
2826 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2829 g_warning ("Could not get request pad from funnel");
2836 gst_element_set_locked_state (priv->funnel, TRUE);
2837 gst_element_set_locked_state (output, TRUE);
2839 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2840 gst_element_set_state (output, GST_STATE_NULL);
2842 gst_bin_remove (GST_BIN (priv->pipeline), output);
2843 gst_element_set_locked_state (output, FALSE);
2847 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2848 priv->funnel = NULL;
2853 /* Called with global lock held */
2855 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2858 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2860 GstPadTemplate *template;
2862 if (!priv->audio_output_added)
2864 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2866 g_warning ("Could not add audio sink to pipeline");
2867 g_object_unref (priv->audio_output);
2868 goto error_add_output;
2871 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2873 g_warning ("Could not start audio sink");
2878 template = gst_element_class_get_pad_template (
2879 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2881 pad = gst_element_request_pad (priv->audio_output,
2882 template, NULL, NULL);
2886 g_warning ("Could not get sink pad from sink");
2893 gst_element_set_locked_state (priv->audio_output, TRUE);
2894 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2895 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2896 priv->audio_output = NULL;
2904 empathy_call_window_update_timer (gpointer user_data)
2906 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2907 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2908 const gchar *status;
2912 time_ = g_timer_elapsed (priv->timer, NULL);
2914 if (priv->call_state == HELD)
2915 status = _("On hold");
2916 else if (!gtk_toggle_tool_button_get_active (
2917 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2920 status = _("Duration");
2922 /* Translators: 'status - minutes:seconds' the caller has been connected */
2923 str = g_strdup_printf (_("%s — %d:%02dm"),
2925 (int) time_ / 60, (int) time_ % 60);
2926 empathy_call_window_status_message (self, str);
2934 EMP_RESPONSE_BALANCE
2938 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2942 switch (response_id)
2944 case GTK_RESPONSE_CLOSE:
2945 gtk_widget_destroy (GTK_WIDGET (info_bar));
2947 case EMP_RESPONSE_BALANCE:
2948 empathy_url_show (GTK_WIDGET (info_bar),
2949 g_object_get_data (G_OBJECT (info_bar), "uri"));
2955 display_error (EmpathyCallWindow *self,
2959 const gchar *details,
2960 const gchar *button_text,
2962 gint button_response)
2964 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2965 GtkWidget *info_bar;
2966 GtkWidget *content_area;
2973 /* Create info bar */
2974 info_bar = gtk_info_bar_new ();
2976 if (button_text != NULL)
2978 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2979 button_text, button_response);
2980 g_object_set_data_full (G_OBJECT (info_bar),
2981 "uri", g_strdup (uri), g_free);
2984 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2985 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
2987 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2989 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2991 /* hbox containing the image and the messages vbox */
2992 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2993 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2996 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2997 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2999 /* vbox containing the main message and the details expander */
3000 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3001 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3004 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3006 label = gtk_label_new (NULL);
3007 gtk_label_set_markup (GTK_LABEL (label), txt);
3008 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3009 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3012 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3015 if (details != NULL)
3017 GtkWidget *expander;
3019 expander = gtk_expander_new (_("Technical Details"));
3021 txt = g_strdup_printf ("<i>%s</i>", details);
3023 label = gtk_label_new (NULL);
3024 gtk_label_set_markup (GTK_LABEL (label), txt);
3025 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3026 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3029 gtk_container_add (GTK_CONTAINER (expander), label);
3030 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3033 g_signal_connect (info_bar, "response",
3034 G_CALLBACK (on_error_infobar_response_cb), NULL);
3036 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3037 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3038 gtk_widget_show_all (info_bar);
3043 media_stream_error_to_txt (EmpathyCallWindow *self,
3044 TpCallChannel *call,
3046 TpMediaStreamError error)
3048 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3049 const gchar *cm = NULL;
3055 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3057 return g_strdup_printf (
3058 _("%s's software does not understand any of the audio formats "
3059 "supported by your computer"),
3060 empathy_contact_get_alias (priv->contact));
3062 return g_strdup_printf (
3063 _("%s's software does not understand any of the video formats "
3064 "supported by your computer"),
3065 empathy_contact_get_alias (priv->contact));
3067 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3068 return g_strdup_printf (
3069 _("Can't establish a connection to %s. "
3070 "One of you might be on a network that does not allow "
3071 "direct connections."),
3072 empathy_contact_get_alias (priv->contact));
3074 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3075 return g_strdup (_("There was a failure on the network"));
3077 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3079 return g_strdup (_("The audio formats necessary for this call "
3080 "are not installed on your computer"));
3082 return g_strdup (_("The video formats necessary for this call "
3083 "are not installed on your computer"));
3085 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3086 tp_connection_parse_object_path (
3087 tp_channel_borrow_connection (TP_CHANNEL (call)),
3090 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3091 "product=Telepathy&component=%s", cm);
3093 result = g_strdup_printf (
3094 _("Something unexpected happened in a Telepathy component. "
3095 "Please <a href=\"%s\">report this bug</a> and attach "
3096 "logs gathered from the 'Debug' window in the Help menu."), url);
3102 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3103 return g_strdup (_("There was a failure in the call engine"));
3105 case TP_MEDIA_STREAM_ERROR_EOS:
3106 return g_strdup (_("The end of the stream was reached"));
3108 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3115 empathy_call_window_stream_error (EmpathyCallWindow *self,
3116 TpCallChannel *call,
3125 desc = media_stream_error_to_txt (self, call, audio, code);
3128 /* No description, use the error message. That's not great as it's not
3129 * localized but it's better than nothing. */
3130 display_error (self, call, icon, title, msg, NULL);
3134 display_error (self, call, icon, title, desc, msg);
3140 empathy_call_window_audio_stream_error (TpCallChannel *call,
3143 EmpathyCallWindow *self)
3145 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3146 "gnome-stock-mic", _("Can't establish audio stream"));
3150 empathy_call_window_video_stream_error (TpCallChannel *call,
3153 EmpathyCallWindow *self)
3155 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3156 "camera-web", _("Can't establish video stream"));
3161 show_balance_error (EmpathyCallWindow *self)
3165 gchar *balance, *tmp;
3166 const gchar *uri, *currency;
3170 g_object_get (self->priv->handler,
3171 "call-channel", &call,
3174 conn = tp_channel_borrow_connection (call);
3175 g_object_unref (call);
3177 uri = tp_connection_get_balance_uri (conn);
3179 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3181 /* unknown balance */
3182 balance = g_strdup ("(--)");
3186 char *money = empathy_format_currency (amount, scale, currency);
3188 balance = g_strdup_printf ("%s %s",
3193 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3195 display_error (self,
3197 _("Sorry, you don’t have enough credit for that call."),
3201 EMP_RESPONSE_BALANCE);
3208 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3211 EmpathyCallWindow *self)
3213 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3214 TpCallChannel *call;
3215 gboolean can_send_video;
3217 if (state == TP_CALL_STATE_ENDED)
3219 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3220 empathy_call_window_disconnected (self, TRUE);
3221 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3222 show_balance_error (self);
3226 if (state != TP_CALL_STATE_ACCEPTED)
3229 if (priv->call_state == CONNECTED)
3232 g_timer_start (priv->timer);
3233 priv->call_state = CONNECTED;
3235 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3237 can_send_video = priv->video_input != NULL &&
3238 empathy_contact_can_voip_video (priv->contact) &&
3239 empathy_camera_monitor_get_available (priv->camera_monitor);
3241 g_object_get (priv->handler, "call-channel", &call, NULL);
3243 if (tp_call_channel_has_dtmf (call))
3244 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3246 if (priv->video_input == NULL)
3247 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3249 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3251 empathy_call_window_show_hangup_button (self, TRUE);
3253 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3255 clutter_actor_hide (priv->video_output);
3256 gtk_widget_show (priv->remote_user_avatar_widget);
3258 g_object_unref (call);
3260 g_mutex_lock (priv->lock);
3262 priv->timer_id = g_timeout_add_seconds (1,
3263 empathy_call_window_update_timer, self);
3265 g_mutex_unlock (priv->lock);
3267 empathy_call_window_update_timer (self);
3269 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3273 empathy_call_window_show_video_output_cb (gpointer user_data)
3275 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3277 if (self->priv->video_output != NULL)
3279 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3280 clutter_actor_show (self->priv->video_output);
3281 empathy_call_window_raise_actors (self);
3288 empathy_call_window_check_video_cb (gpointer data)
3290 EmpathyCallWindow *self = data;
3292 if (self->priv->got_video)
3294 self->priv->got_video = FALSE;
3298 /* No video in the last N seconds, display the remote avatar */
3299 empathy_call_window_show_video_output (self, FALSE);
3304 /* Called from the streaming thread */
3306 empathy_call_window_video_probe_cb (GstPad *pad,
3307 GstMiniObject *mini_obj,
3308 EmpathyCallWindow *self)
3311 if (GST_IS_EVENT (mini_obj))
3314 if (G_UNLIKELY (!self->priv->got_video))
3316 /* show the remote video */
3317 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3318 empathy_call_window_show_video_output_cb,
3319 g_object_ref (self), g_object_unref);
3321 self->priv->got_video = TRUE;
3327 /* Called from the streaming thread */
3329 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3330 TfContent *content, GstPad *src, gpointer user_data)
3332 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3333 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3334 gboolean retval = FALSE;
3339 g_mutex_lock (priv->lock);
3341 g_object_get (content, "media-type", &media_type, NULL);
3345 case TP_MEDIA_STREAM_TYPE_AUDIO:
3346 pad = empathy_call_window_get_audio_sink_pad (self, content);
3348 case TP_MEDIA_STREAM_TYPE_VIDEO:
3349 g_idle_add (empathy_call_window_show_video_output_cb, self);
3350 pad = empathy_call_window_get_video_sink_pad (self);
3352 gst_pad_add_data_probe (src,
3353 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3354 if (priv->got_video_src > 0)
3355 g_source_remove (priv->got_video_src);
3356 priv->got_video_src = g_timeout_add_seconds (1,
3357 empathy_call_window_check_video_cb, self);
3360 g_assert_not_reached ();
3366 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3367 g_warning ("Could not link %s sink pad",
3368 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3372 gst_object_unref (pad);
3376 /* If no sink could be linked, try to add fakesink to prevent the whole call
3381 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3383 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3385 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3386 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3387 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3389 gst_element_set_locked_state (fakesink, TRUE);
3390 gst_element_set_state (fakesink, GST_STATE_NULL);
3391 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3395 DEBUG ("Could not link real sink, linked fakesink instead");
3397 gst_object_unref (sinkpad);
3401 gst_object_unref (fakesink);
3406 g_mutex_unlock (priv->lock);
3412 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3415 EmpathyCallWindowPriv *priv = self->priv;
3417 g_assert (priv->audio_output_added == FALSE);
3418 g_assert (priv->audio_output == FALSE);
3420 priv->audio_output = empathy_audio_sink_new ();
3421 g_object_ref_sink (priv->audio_output);
3423 /* volume button to output volume linking */
3424 g_object_bind_property (priv->audio_output, "volume",
3425 priv->volume_button, "value",
3426 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3428 g_object_bind_property_full (content, "requested-output-volume",
3429 priv->audio_output, "volume",
3431 audio_control_volume_to_element,
3432 element_volume_to_audio_control,
3435 /* Link volumes together, sync the current audio input volume property
3436 * back to farstream first */
3437 g_object_bind_property_full (priv->audio_output, "volume",
3438 content, "reported-output-volume",
3439 G_BINDING_SYNC_CREATE,
3440 element_volume_to_audio_control,
3441 audio_control_volume_to_element,
3444 /* For raw audio conferences assume that the producer of the raw data
3445 * has already processed it, so turn off any echo cancellation and any
3446 * other audio improvements that come with it */
3447 empathy_audio_sink_set_echo_cancel (
3448 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3449 !empathy_call_window_content_is_raw (content));
3454 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3455 TfContent *content, gpointer user_data)
3457 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3458 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3460 FsMediaType media_type;
3461 gboolean retval = FALSE;
3463 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3464 g_assert (sink != NULL);
3468 case FS_MEDIA_TYPE_AUDIO:
3470 /* For raw audio conferences assume that the receiver of the raw data
3471 * wants it unprocessed, so turn off any echo cancellation and any
3472 * other audio improvements that come with it */
3473 empathy_audio_src_set_echo_cancel (
3474 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3475 !empathy_call_window_content_is_raw (content));
3477 /* Link volumes together, sync the current audio input volume property
3478 * back to farstream first */
3479 g_object_bind_property_full (content, "requested-input-volume",
3480 priv->audio_input, "volume",
3482 audio_control_volume_to_element,
3483 element_volume_to_audio_control,
3486 g_object_bind_property_full (priv->audio_input, "volume",
3487 content, "reported-input-volume",
3488 G_BINDING_SYNC_CREATE,
3489 element_volume_to_audio_control,
3490 audio_control_volume_to_element,
3493 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3495 g_warning ("Could not add audio source to pipeline");
3499 pad = gst_element_get_static_pad (priv->audio_input, "src");
3502 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3503 g_warning ("Could not get source pad from audio source");
3507 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3509 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3510 gst_object_unref (pad);
3511 g_warning ("Could not link audio source to farsight");
3514 gst_object_unref (pad);
3516 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3518 g_warning ("Could not start audio source");
3519 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3520 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3524 /* Prepare our audio output, not added yet though */
3525 empathy_call_window_prepare_audio_output (self, content);
3529 case FS_MEDIA_TYPE_VIDEO:
3530 if (priv->video_tee != NULL)
3532 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3533 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3535 g_warning ("Could not link video source input pipeline");
3538 gst_object_unref (pad);
3544 g_assert_not_reached ();
3547 gst_object_unref (sink);
3552 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3554 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3555 GstElement *preview;
3557 disable_camera (self);
3559 DEBUG ("remove video input");
3560 preview = priv->video_preview_sink;
3562 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3563 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3564 gst_element_set_state (preview, GST_STATE_NULL);
3566 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3569 g_object_unref (priv->video_input);
3570 priv->video_input = NULL;
3571 g_object_unref (priv->video_tee);
3572 priv->video_tee = NULL;
3573 clutter_actor_destroy (priv->video_preview);
3574 priv->video_preview = NULL;
3576 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3580 start_call (EmpathyCallWindow *self)
3582 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3584 priv->call_started = TRUE;
3585 empathy_call_handler_start_call (priv->handler,
3586 gtk_get_current_event_time ());
3588 if (empathy_call_handler_has_initial_video (priv->handler))
3590 TpCallChannel *call;
3593 g_object_get (priv->handler, "call-channel", &call, NULL);
3594 /* If the call channel isn't set yet we're requesting it, if we're
3595 * requesting it with initial video it should be PENDING_SEND when we get
3598 s = TP_SENDING_STATE_PENDING_SEND;
3600 s = empathy_call_channel_get_video_state (call);
3602 if (s == TP_SENDING_STATE_PENDING_SEND ||
3603 s == TP_SENDING_STATE_SENDING)
3605 /* Enable 'send video' buttons and display the preview */
3606 gtk_toggle_tool_button_set_active (
3607 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3611 gtk_toggle_tool_button_set_active (
3612 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3614 if (priv->video_preview == NULL)
3616 create_video_preview (self);
3617 add_video_preview_to_pipeline (self);
3622 g_object_unref (call);
3627 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3630 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3631 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3632 GstState newstate, pending;
3634 empathy_call_handler_bus_message (priv->handler, bus, message);
3636 switch (GST_MESSAGE_TYPE (message))
3638 case GST_MESSAGE_STATE_CHANGED:
3639 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3641 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3643 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3644 !priv->call_started)
3646 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3647 if (newstate == GST_STATE_PAUSED)
3649 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3650 priv->pipeline_playing = TRUE;
3652 if (priv->start_call_when_playing)
3656 if (priv->video_preview_sink != NULL &&
3657 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3659 gst_message_parse_state_changed (message, NULL, &newstate,
3662 if (newstate == GST_STATE_PLAYING &&
3663 pending == GST_STATE_VOID_PENDING)
3664 empathy_call_window_stop_camera_spinning (self);
3667 case GST_MESSAGE_ERROR:
3669 GError *error = NULL;
3670 GstElement *gst_error;
3673 gst_message_parse_error (message, &error, &debug);
3674 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3676 g_message ("Element error: %s -- %s\n", error->message, debug);
3678 if (g_str_has_prefix (gst_element_get_name (gst_error),
3679 VIDEO_INPUT_ERROR_PREFIX))
3681 /* Remove the video input and continue */
3682 if (priv->video_input != NULL)
3683 empathy_call_window_remove_video_input (self);
3684 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3688 empathy_call_window_disconnected (self, TRUE);
3690 g_error_free (error);
3693 case GST_MESSAGE_UNKNOWN:
3694 case GST_MESSAGE_EOS:
3695 case GST_MESSAGE_WARNING:
3696 case GST_MESSAGE_INFO:
3697 case GST_MESSAGE_TAG:
3698 case GST_MESSAGE_BUFFERING:
3699 case GST_MESSAGE_STATE_DIRTY:
3700 case GST_MESSAGE_STEP_DONE:
3701 case GST_MESSAGE_CLOCK_PROVIDE:
3702 case GST_MESSAGE_CLOCK_LOST:
3703 case GST_MESSAGE_NEW_CLOCK:
3704 case GST_MESSAGE_STRUCTURE_CHANGE:
3705 case GST_MESSAGE_STREAM_STATUS:
3706 case GST_MESSAGE_APPLICATION:
3707 case GST_MESSAGE_ELEMENT:
3708 case GST_MESSAGE_SEGMENT_START:
3709 case GST_MESSAGE_SEGMENT_DONE:
3710 case GST_MESSAGE_DURATION:
3711 case GST_MESSAGE_ANY:
3720 empathy_call_window_members_changed_cb (TpCallChannel *call,
3721 GHashTable *updates,
3723 TpCallStateReason *reason,
3724 EmpathyCallWindow *self)
3726 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3727 GHashTableIter iter;
3728 gpointer key, value;
3729 gboolean held = FALSE;
3731 g_hash_table_iter_init (&iter, updates);
3732 while (g_hash_table_iter_next (&iter, &key, &value))
3734 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3736 /* This assumes this is a 1-1 call, otherwise one participant
3737 * putting the call on hold wouldn't mean the call is on hold
3745 priv->call_state = HELD;
3746 else if (priv->call_state == HELD)
3747 priv->call_state = CONNECTED;
3751 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3753 EmpathyCallWindow *self)
3755 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3756 TpCallChannel *call;
3758 g_object_get (priv->handler, "call-channel", &call, NULL);
3763 tp_g_signal_connect_object (call, "audio-stream-error",
3764 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3765 tp_g_signal_connect_object (call, "video-stream-error",
3766 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3769 tp_g_signal_connect_object (call, "members-changed",
3770 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3772 g_object_unref (call);
3776 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3778 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3779 TpCallChannel *call;
3781 g_signal_connect (priv->handler, "state-changed",
3782 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3783 g_signal_connect (priv->handler, "conference-added",
3784 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3785 g_signal_connect (priv->handler, "conference-removed",
3786 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3787 g_signal_connect (priv->handler, "closed",
3788 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3789 g_signal_connect (priv->handler, "src-pad-added",
3790 G_CALLBACK (empathy_call_window_src_added_cb), self);
3791 g_signal_connect (priv->handler, "content-added",
3792 G_CALLBACK (empathy_call_window_content_added_cb), self);
3793 g_signal_connect (priv->handler, "content-removed",
3794 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3796 /* We connect to ::call-channel unconditionally since we'll
3797 * get new channels if we hangup and redial or if we reuse the
3799 g_signal_connect (priv->handler, "notify::call-channel",
3800 G_CALLBACK (call_handler_notify_call_cb), self);
3802 g_signal_connect (priv->handler, "framerate-changed",
3803 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3804 g_signal_connect (priv->handler, "resolution-changed",
3805 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3807 g_object_get (priv->handler, "call-channel", &call, NULL);
3810 /* We won't get notify::call-channel for this channel, so
3811 * directly call the callback. */
3812 call_handler_notify_call_cb (priv->handler, NULL, self);
3813 g_object_unref (call);
3818 empathy_call_window_realized_cb (GtkWidget *widget,
3819 EmpathyCallWindow *self)
3823 /* Make the hangup button twice as wide */
3824 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3825 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3827 empathy_call_window_connect_handler (self);
3829 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3833 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3834 EmpathyCallWindow *window)
3836 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3838 if (priv->pipeline != NULL)
3840 if (priv->bus_message_source_id != 0)
3842 g_source_remove (priv->bus_message_source_id);
3843 priv->bus_message_source_id = 0;
3846 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3849 if (priv->call_state == CONNECTING)
3850 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3856 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3859 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3861 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3866 gtk_widget_hide (priv->dtmf_panel);
3867 gtk_widget_hide (menu);
3868 gtk_widget_hide (priv->toolbar);
3872 if (priv->dialpad_was_visible_before_fs)
3873 gtk_widget_show (priv->dtmf_panel);
3875 gtk_widget_show (menu);
3876 gtk_widget_show (priv->toolbar);
3878 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3879 priv->original_height_before_fs);
3884 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3886 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3888 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3889 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3890 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3891 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3893 if (priv->video_output != NULL)
3896 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3897 priv->video_output, TRUE, TRUE,
3898 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3905 empathy_call_window_state_event_cb (GtkWidget *widget,
3906 GdkEventWindowState *event, EmpathyCallWindow *window)
3908 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3910 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3911 gboolean set_fullscreen = event->new_window_state &
3912 GDK_WINDOW_STATE_FULLSCREEN;
3916 gboolean dialpad_was_visible;
3917 GtkAllocation allocation;
3918 gint original_width, original_height;
3920 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3921 original_width = allocation.width;
3922 original_height = allocation.height;
3924 g_object_get (priv->dtmf_panel,
3925 "visible", &dialpad_was_visible,
3928 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3929 priv->original_width_before_fs = original_width;
3930 priv->original_height_before_fs = original_height;
3932 if (priv->video_output_motion_handler_id == 0 &&
3933 priv->video_output != NULL)
3935 priv->video_output_motion_handler_id = g_signal_connect (
3936 G_OBJECT (priv->video_container), "motion-notify-event",
3937 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3943 disconnect_video_output_motion_handler (window);
3946 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3948 show_controls (window, set_fullscreen);
3949 show_borders (window, set_fullscreen);
3950 gtk_action_set_stock_id (priv->menu_fullscreen,
3951 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3952 priv->is_fullscreen = set_fullscreen;
3959 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3962 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3963 int w, h, dialpad_width;
3964 GtkAllocation allocation;
3966 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3967 w = allocation.width;
3968 h = allocation.height;
3970 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3974 gtk_widget_show (priv->dtmf_panel);
3980 gtk_widget_hide (priv->dtmf_panel);
3984 gtk_window_resize (GTK_WINDOW (window), w, h);
3988 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3991 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3992 TpCallChannel *call;
3994 priv->sending_video = (state == CAMERA_STATE_ON);
3996 if (state == CAMERA_STATE_ON)
3998 /* When we start sending video, we want to show the video preview by
4000 display_video_preview (window, TRUE);
4004 display_video_preview (window, FALSE);
4007 if (priv->call_state != CONNECTED)
4010 g_object_get (priv->handler, "call-channel", &call, NULL);
4011 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4012 empathy_call_channel_send_video (call, priv->sending_video);
4013 g_object_unref (call);
4017 empathy_call_window_hangup_cb (gpointer object,
4018 EmpathyCallWindow *self)
4020 /* stopping the call will put it the ENDED state and
4021 * from state_changed_cb we'll reconfigure the window
4023 empathy_call_handler_stop_call (self->priv->handler);
4027 empathy_call_window_restart_call (EmpathyCallWindow *window)
4029 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4031 /* Remove error info bars */
4032 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4033 (GtkCallback) gtk_widget_destroy, NULL);
4035 create_video_output_widget (window);
4036 priv->outgoing = TRUE;
4037 empathy_call_window_set_state_connecting (window);
4039 if (priv->pipeline_playing)
4040 start_call (window);
4042 /* call will be started when the pipeline is ready */
4043 priv->start_call_when_playing = TRUE;
4045 empathy_call_window_setup_avatars (window, priv->handler);
4047 empathy_call_window_show_hangup_button (window, TRUE);
4051 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4052 EmpathyCallWindow *window)
4056 active = gtk_toggle_tool_button_get_active (button);
4058 empathy_call_window_show_dialpad (window, active);
4062 empathy_call_window_fullscreen_cb (gpointer object,
4063 EmpathyCallWindow *window)
4065 empathy_call_window_fullscreen_toggle (window);
4069 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4071 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4073 if (priv->is_fullscreen)
4074 gtk_window_unfullscreen (GTK_WINDOW (window));
4076 gtk_window_fullscreen (GTK_WINDOW (window));
4080 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4081 GdkEventButton *event, EmpathyCallWindow *window)
4083 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4085 empathy_call_window_video_menu_popup (window, event->button);
4093 empathy_call_window_key_press_cb (GtkWidget *video_output,
4094 GdkEventKey *event, EmpathyCallWindow *window)
4096 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4098 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4100 /* Since we are in fullscreen mode, toggling will bring us back to
4102 empathy_call_window_fullscreen_toggle (window);
4110 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4111 GdkEventMotion *event, EmpathyCallWindow *window)
4113 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4115 if (priv->is_fullscreen)
4117 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4119 /* Show the bottom toolbar */
4120 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4127 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4131 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4133 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4135 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4136 button, gtk_get_current_event_time ());
4137 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4141 empathy_call_window_status_message (EmpathyCallWindow *self,
4144 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4148 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4150 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4152 return priv->ui_manager;
4155 EmpathyGstAudioSrc *
4156 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4158 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4160 return (EmpathyGstAudioSrc *) priv->audio_input;
4163 EmpathyGstVideoSrc *
4164 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4166 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4170 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4171 const gchar *device)
4173 EmpathyGstVideoSrc *video;
4176 /* Restart the camera only if it's already running */
4177 running = (self->priv->video_preview != NULL);
4178 video = empathy_call_window_get_video_src (self);
4181 empathy_call_window_play_camera (self, FALSE);
4183 empathy_video_src_change_device (video, device);
4186 empathy_call_window_play_camera (self, TRUE);