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
27 #include <gdk/gdkkeysyms.h>
30 #include <glib/gi18n.h>
32 #include <clutter/clutter.h>
33 #include <clutter-gtk/clutter-gtk.h>
34 #include <clutter-gst/clutter-gst.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/util.h>
40 #include <gst/farsight/fs-element-added-notifier.h>
41 #include <gst/farsight/fs-utils.h>
43 #include <libempathy/empathy-camera-monitor.h>
44 #include <libempathy/empathy-gsettings.h>
45 #include <libempathy/empathy-tp-contact-factory.h>
46 #include <libempathy/empathy-request-util.h>
47 #include <libempathy/empathy-utils.h>
49 #include <libempathy-gtk/empathy-avatar-image.h>
50 #include <libempathy-gtk/empathy-ui-utils.h>
51 #include <libempathy-gtk/empathy-sound-manager.h>
52 #include <libempathy-gtk/empathy-geometry.h>
53 #include <libempathy-gtk/empathy-images.h>
55 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
56 #include <libempathy/empathy-debug.h>
58 #include "empathy-call-window.h"
59 #include "empathy-call-window-fullscreen.h"
60 #include "empathy-call-factory.h"
61 #include "empathy-video-widget.h"
62 #include "empathy-about-dialog.h"
63 #include "empathy-audio-src.h"
64 #include "empathy-audio-sink.h"
65 #include "empathy-video-src.h"
66 #include "empathy-mic-menu.h"
67 #include "empathy-preferences.h"
68 #include "empathy-rounded-actor.h"
69 #include "empathy-rounded-rectangle.h"
70 #include "empathy-rounded-texture.h"
71 #include "empathy-camera-menu.h"
73 #define CONTENT_HBOX_BORDER_WIDTH 6
74 #define CONTENT_HBOX_SPACING 3
75 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
77 #define SELF_VIDEO_SECTION_WIDTH 120
78 #define SELF_VIDEO_SECTION_HEIGHT 90
79 #define SELF_VIDEO_SECTION_MARGIN 10
81 #define FLOATING_TOOLBAR_OPACITY 192
82 #define FLOATING_TOOLBAR_WIDTH 280
83 #define FLOATING_TOOLBAR_HEIGHT 36
84 #define FLOATING_TOOLBAR_SPACING 20
86 /* The avatar's default width and height are set to the same value because we
87 want a square icon. */
88 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
89 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
90 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
92 #define SMALL_TOOLBAR_SIZE 36
94 /* If an video input error occurs, the error message will start with "v4l" */
95 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
97 /* The time interval in milliseconds between 2 outgoing rings */
98 #define MS_BETWEEN_RING 500
100 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
103 PROP_CALL_HANDLER = 1,
107 RINGING, /* Incoming call */
108 CONNECTING, /* Outgoing call */
109 CONNECTED, /* Connected */
110 HELD, /* Connected, but on hold */
111 DISCONNECTED, /* Disconnected */
112 REDIALING /* Redialing (special case of CONNECTING) */
116 CAMERA_STATE_OFF = 0,
122 PREVIEW_POS_TOP_LEFT,
123 PREVIEW_POS_TOP_RIGHT,
124 PREVIEW_POS_BOTTOM_LEFT,
125 PREVIEW_POS_BOTTOM_RIGHT,
128 struct _EmpathyCallWindowPriv
130 gboolean dispose_has_run;
131 EmpathyCallHandler *handler;
133 EmpathyContact *contact;
135 EmpathyCameraMonitor *camera_monitor;
140 GtkUIManager *ui_manager;
141 GtkWidget *errors_vbox;
142 /* widget displays the video received from the remote user. This widget is
143 * alive only during call. */
144 ClutterActor *video_output;
145 ClutterActor *video_preview;
146 ClutterActor *drag_preview;
147 ClutterActor *preview_shown_button;
148 ClutterActor *preview_hidden_button;
149 ClutterActor *preview_rectangle1;
150 ClutterActor *preview_rectangle2;
151 ClutterActor *preview_rectangle3;
152 ClutterActor *preview_rectangle4;
153 ClutterActor *preview_rectangle_box1;
154 ClutterActor *preview_rectangle_box2;
155 ClutterActor *preview_rectangle_box3;
156 ClutterActor *preview_rectangle_box4;
157 ClutterActor *preview_spinner_actor;
158 GtkWidget *preview_spinner_widget;
159 GtkWidget *video_container;
160 GtkWidget *remote_user_avatar_widget;
161 GtkWidget *remote_user_avatar_toolbar;
162 GtkWidget *remote_user_name_toolbar;
163 GtkWidget *status_label;
164 GtkWidget *hangup_button;
165 GtkWidget *audio_call_button;
166 GtkWidget *video_call_button;
167 GtkWidget *mic_button;
168 GtkWidget *camera_button;
169 GtkWidget *dialpad_button;
171 GtkWidget *bottom_toolbar;
172 ClutterActor *floating_toolbar;
174 GtkAction *menu_fullscreen;
175 GtkAction *menu_swap_camera;
177 ClutterState *transitions;
179 /* The box that contains self and remote avatar and video
180 input/output. When we redial, we destroy and re-create the box */
181 ClutterActor *video_box;
182 ClutterLayoutManager *video_layout;
184 /* Coordinates of the preview drag event's start. */
185 PreviewPosition preview_pos;
187 /* We keep a reference on the hbox which contains the main content so we can
188 easilly repack everything when toggling fullscreen */
189 GtkWidget *content_hbox;
191 /* These are used to accept or reject an incoming call when the status
193 GtkWidget *incoming_call_dialog;
194 TpyCallChannel *pending_channel;
195 TpChannelDispatchOperation *pending_cdo;
196 TpAddDispatchOperationContext *pending_context;
198 gulong video_output_motion_handler_id;
199 guint bus_message_source_id;
203 /* String that contains the queued tones to send after the current ones
206 gboolean sending_tones;
207 GtkWidget *dtmf_panel;
210 GtkWidget *details_vbox;
211 GtkWidget *vcodec_encoding_label;
212 GtkWidget *acodec_encoding_label;
213 GtkWidget *vcodec_decoding_label;
214 GtkWidget *acodec_decoding_label;
216 GtkWidget *audio_remote_candidate_label;
217 GtkWidget *audio_local_candidate_label;
218 GtkWidget *video_remote_candidate_label;
219 GtkWidget *video_local_candidate_label;
220 GtkWidget *video_remote_candidate_info_img;
221 GtkWidget *video_local_candidate_info_img;
222 GtkWidget *audio_remote_candidate_info_img;
223 GtkWidget *audio_local_candidate_info_img;
225 GstElement *video_input;
226 GstElement *video_preview_sink;
227 GstElement *video_output_sink;
228 GstElement *audio_input;
229 GstElement *audio_output;
230 GstElement *pipeline;
231 GstElement *video_tee;
241 gboolean call_started;
242 gboolean sending_video;
243 CameraState camera_state;
245 EmpathyCallWindowFullscreen *fullscreen;
246 gboolean is_fullscreen;
251 guint inactivity_src;
253 /* Those fields represent the state of the window before it actually was in
255 gboolean dialpad_was_visible_before_fs;
256 gint original_width_before_fs;
257 gint original_height_before_fs;
259 gint x, y, w, h, dialpad_width;
262 /* TRUE if the call should be started when the pipeline is playing */
263 gboolean start_call_when_playing;
264 /* TRUE if we requested to set the pipeline in the playing state */
265 gboolean pipeline_playing;
267 EmpathySoundManager *sound_mgr;
270 EmpathyMicMenu *mic_menu;
271 EmpathyCameraMenu *camera_menu;
274 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
276 static void empathy_call_window_realized_cb (GtkWidget *widget,
277 EmpathyCallWindow *window);
279 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
280 GdkEvent *event, EmpathyCallWindow *window);
282 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
283 GdkEventWindowState *event, EmpathyCallWindow *window);
285 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
288 static void empathy_call_window_mic_toggled_cb (
289 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
291 static void empathy_call_window_hangup_cb (gpointer object,
292 EmpathyCallWindow *window);
294 static void empathy_call_window_fullscreen_cb (gpointer object,
295 EmpathyCallWindow *window);
297 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
299 static gboolean empathy_call_window_video_button_press_cb (
300 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
302 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
303 GdkEventKey *event, EmpathyCallWindow *window);
305 static gboolean empathy_call_window_video_output_motion_notify (
306 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
308 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
311 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
313 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
314 EmpathyCallWindow *window);
316 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
318 static void empathy_call_window_status_message (EmpathyCallWindow *window,
321 static gboolean empathy_call_window_bus_message (GstBus *bus,
322 GstMessage *message, gpointer user_data);
325 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
326 gdouble value, EmpathyCallWindow *window);
329 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
332 gtk_widget_set_visible (self->priv->hangup_button, show);
333 gtk_widget_set_visible (self->priv->audio_call_button, !show);
334 gtk_widget_set_visible (self->priv->video_call_button, !show);
338 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
339 EmpathyCallWindow *self)
341 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
342 empathy_call_window_restart_call (self);
346 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
347 EmpathyCallWindow *self)
349 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
350 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
351 empathy_call_window_restart_call (self);
355 empathy_call_window_emit_tones (EmpathyCallWindow *self)
359 if (tp_str_empty (self->priv->tones->str))
362 g_object_get (self->priv->handler, "call-channel", &channel, NULL);
364 DEBUG ("Emitting multiple tones: %s", self->priv->tones->str);
366 tp_cli_channel_interface_dtmf_call_multiple_tones (channel, -1,
367 self->priv->tones->str,
368 NULL, NULL, NULL, NULL);
370 self->priv->sending_tones = TRUE;
372 g_string_set_size (self->priv->tones, 0);
374 g_object_unref (channel);
378 empathy_call_window_maybe_emit_tones (EmpathyCallWindow *self)
380 if (self->priv->sending_tones)
383 empathy_call_window_emit_tones (self);
387 empathy_call_window_tones_stopped_cb (TpChannel *proxy,
388 gboolean arg_cancelled,
390 GObject *weak_object)
392 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
394 self->priv->sending_tones = FALSE;
396 empathy_call_window_emit_tones (self);
400 dtmf_button_pressed_cb (GtkButton *button,
401 EmpathyCallWindow *self)
403 EmpathyCallWindowPriv *priv = GET_PRIV (self);
407 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
408 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
411 g_string_append_c (priv->tones, tp_dtmf_event_to_char (event));
413 empathy_call_window_maybe_emit_tones (self);
416 /* empathy_create_dtmf_dialpad() requires a callback, even if empty */
418 dtmf_button_released_cb (GtkButton *button,
419 EmpathyCallWindow *self)
424 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
426 EmpathyCallWindowPriv *priv = GET_PRIV (self);
429 volume = g_settings_get_double (priv->settings,
430 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
432 /* Don't store the volume because of muting */
433 if (volume > 0 || gtk_toggle_tool_button_get_active (
434 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
435 priv->volume = volume;
437 /* Ensure that the toggle button is active if the volume is > 0 and inactive
438 * if it's smaller than 0 */
439 if ((volume > 0) != gtk_toggle_tool_button_get_active (
440 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
441 gtk_toggle_tool_button_set_active (
442 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
444 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
449 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
451 EmpathyCallWindow *self)
453 empathy_call_window_mic_volume_changed (self);
457 empathy_call_window_raise_actors (EmpathyCallWindow *self)
459 clutter_actor_raise_top (self->priv->floating_toolbar);
461 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
462 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
463 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
464 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
468 empathy_call_window_show_video_output (EmpathyCallWindow *self,
471 if (self->priv->video_output != NULL)
472 g_object_set (self->priv->video_output, "visible", show, NULL);
474 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
476 empathy_call_window_raise_actors (self);
480 create_video_output_widget (EmpathyCallWindow *self)
482 EmpathyCallWindowPriv *priv = GET_PRIV (self);
484 g_assert (priv->video_output == NULL);
485 g_assert (priv->pipeline != NULL);
487 priv->video_output = clutter_texture_new ();
489 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
492 priv->video_output_sink = clutter_gst_video_sink_new (
493 CLUTTER_TEXTURE (priv->video_output));
495 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
498 gtk_widget_add_events (priv->video_container,
499 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
500 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
501 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
505 create_video_input (EmpathyCallWindow *self)
507 EmpathyCallWindowPriv *priv = GET_PRIV (self);
509 g_assert (priv->video_input == NULL);
510 priv->video_input = empathy_video_src_new ();
511 gst_object_ref (priv->video_input);
512 gst_object_sink (priv->video_input);
516 create_audio_input (EmpathyCallWindow *self)
518 EmpathyCallWindowPriv *priv = GET_PRIV (self);
520 g_assert (priv->audio_input == NULL);
521 priv->audio_input = empathy_audio_src_new ();
522 gst_object_ref (priv->audio_input);
523 gst_object_sink (priv->audio_input);
527 add_video_preview_to_pipeline (EmpathyCallWindow *self)
529 EmpathyCallWindowPriv *priv = GET_PRIV (self);
532 g_assert (priv->video_preview != NULL);
533 g_assert (priv->pipeline != NULL);
534 g_assert (priv->video_input != NULL);
535 g_assert (priv->video_tee != NULL);
537 preview = priv->video_preview_sink;
539 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
541 g_warning ("Could not add video input to pipeline");
545 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
547 g_warning ("Could not add video preview to pipeline");
551 if (!gst_element_link (priv->video_input, priv->video_tee))
553 g_warning ("Could not link video input to video tee");
557 if (!gst_element_link (priv->video_tee, preview))
559 g_warning ("Could not link video tee to video preview");
565 empathy_call_window_disable_camera_cb (GtkAction *action,
566 EmpathyCallWindow *self)
568 clutter_actor_destroy (self->priv->preview_hidden_button);
570 gtk_toggle_tool_button_set_active (
571 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
575 empathy_call_window_minimise_camera_cb (GtkAction *action,
576 EmpathyCallWindow *self)
578 clutter_actor_hide (self->priv->video_preview);
579 clutter_actor_show (self->priv->preview_hidden_button);
583 empathy_call_window_maximise_camera_cb (GtkAction *action,
584 EmpathyCallWindow *self)
586 clutter_actor_show (self->priv->video_preview);
587 clutter_actor_hide (self->priv->preview_hidden_button);
591 empathy_call_window_swap_camera_cb (GtkAction *action,
592 EmpathyCallWindow *self)
594 const GList *cameras, *l;
597 DEBUG ("Swapping the camera");
599 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
600 current_cam = empathy_video_src_dup_device (
601 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
603 for (l = cameras; l != NULL; l = l->next)
605 EmpathyCamera *camera = l->data;
607 if (!tp_strdiff (camera->device, current_cam))
612 next = l->next->data;
614 next = cameras->data;
616 /* EmpathyCameraMenu will update itself and do the actual change
618 g_settings_set_string (self->priv->settings,
619 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
626 g_free (current_cam);
630 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
631 EmpathyCamera *camera,
632 EmpathyCallWindow *self)
634 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
636 gtk_action_set_visible (self->priv->menu_swap_camera,
637 g_list_length ((GList *) cameras) >= 2);
641 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
642 EmpathyCamera *camera,
643 EmpathyCallWindow *self)
645 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
647 gtk_action_set_visible (self->priv->menu_swap_camera,
648 g_list_length ((GList *) cameras) >= 2);
652 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
653 EmpathyCallWindow *self)
657 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
659 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
660 0, gtk_get_current_event_time ());
661 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
665 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
666 EmpathyCallWindow *self)
670 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
671 "/preview-hidden-menu");
672 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
673 0, gtk_get_current_event_time ());
674 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
677 static ClutterActor *
678 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
680 ClutterBinAlignment x,
681 ClutterBinAlignment y)
683 ClutterLayoutManager *layout1, *layout2;
684 ClutterActor *rectangle;
685 ClutterActor *box1, *box2;
687 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
688 CLUTTER_BIN_ALIGNMENT_START);
690 box1 = clutter_box_new (layout1);
694 rectangle = empathy_rounded_rectangle_new (
695 SELF_VIDEO_SECTION_WIDTH + 5,
696 SELF_VIDEO_SECTION_HEIGHT + 5);
698 clutter_actor_set_size (box1,
699 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
700 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
701 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
703 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
704 CLUTTER_BIN_ALIGNMENT_CENTER);
706 /* We have a box with the margins and the video in the middle inside
707 * a bigger box with an extra bottom margin so we're not on top of
708 * the floating toolbar. */
709 box2 = clutter_box_new (layout2);
711 clutter_actor_set_size (box2,
712 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
713 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
715 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
716 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
718 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
721 clutter_actor_hide (rectangle);
727 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
729 self->priv->preview_rectangle1 =
730 empathy_call_window_create_preview_rectangle (self,
731 &self->priv->preview_rectangle_box1,
732 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
733 self->priv->preview_rectangle2 =
734 empathy_call_window_create_preview_rectangle (self,
735 &self->priv->preview_rectangle_box2,
736 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
737 self->priv->preview_rectangle3 =
738 empathy_call_window_create_preview_rectangle (self,
739 &self->priv->preview_rectangle_box3,
740 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
741 self->priv->preview_rectangle4 =
742 empathy_call_window_create_preview_rectangle (self,
743 &self->priv->preview_rectangle_box4,
744 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
748 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
751 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
752 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
753 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
754 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
758 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
763 guint ret_x = 0, ret_y = 0;
766 if (!clutter_actor_has_allocation (self->priv->video_box))
769 clutter_actor_get_geometry (self->priv->video_box, &box);
773 case PREVIEW_POS_TOP_LEFT:
774 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
776 case PREVIEW_POS_TOP_RIGHT:
777 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
778 - SELF_VIDEO_SECTION_WIDTH;
779 ret_y = SELF_VIDEO_SECTION_MARGIN;
781 case PREVIEW_POS_BOTTOM_LEFT:
782 ret_x = SELF_VIDEO_SECTION_MARGIN;
783 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
784 - SELF_VIDEO_SECTION_HEIGHT
785 - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING;
787 case PREVIEW_POS_BOTTOM_RIGHT:
788 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
789 - SELF_VIDEO_SECTION_WIDTH;
790 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
791 - SELF_VIDEO_SECTION_HEIGHT - FLOATING_TOOLBAR_HEIGHT
792 - FLOATING_TOOLBAR_SPACING;
795 g_warn_if_reached ();
806 static PreviewPosition
807 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
812 PreviewPosition pos = PREVIEW_POS_NONE;
814 if (!clutter_actor_has_allocation (self->priv->video_box))
817 clutter_actor_get_geometry (self->priv->video_box, &box);
819 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
820 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
821 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
822 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
824 pos = PREVIEW_POS_TOP_LEFT;
826 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
827 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
828 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
829 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
831 pos = PREVIEW_POS_TOP_RIGHT;
833 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
834 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
835 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
836 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
838 pos = PREVIEW_POS_BOTTOM_LEFT;
840 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
841 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
842 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
843 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
845 pos = PREVIEW_POS_BOTTOM_RIGHT;
851 static ClutterActor *
852 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
855 ClutterActor *rectangle;
859 case PREVIEW_POS_TOP_LEFT:
860 rectangle = self->priv->preview_rectangle1;
862 case PREVIEW_POS_TOP_RIGHT:
863 rectangle = self->priv->preview_rectangle3;
865 case PREVIEW_POS_BOTTOM_LEFT:
866 rectangle = self->priv->preview_rectangle2;
868 case PREVIEW_POS_BOTTOM_RIGHT:
869 rectangle = self->priv->preview_rectangle4;
879 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
882 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
884 DEBUG ("moving the video preview to %d", pos);
886 self->priv->preview_pos = pos;
890 case PREVIEW_POS_TOP_LEFT:
891 clutter_bin_layout_set_alignment (layout,
892 self->priv->video_preview,
893 CLUTTER_BIN_ALIGNMENT_START,
894 CLUTTER_BIN_ALIGNMENT_START);
896 case PREVIEW_POS_TOP_RIGHT:
897 clutter_bin_layout_set_alignment (layout,
898 self->priv->video_preview,
899 CLUTTER_BIN_ALIGNMENT_END,
900 CLUTTER_BIN_ALIGNMENT_START);
902 case PREVIEW_POS_BOTTOM_LEFT:
903 clutter_bin_layout_set_alignment (layout,
904 self->priv->video_preview,
905 CLUTTER_BIN_ALIGNMENT_START,
906 CLUTTER_BIN_ALIGNMENT_END);
908 case PREVIEW_POS_BOTTOM_RIGHT:
909 clutter_bin_layout_set_alignment (layout,
910 self->priv->video_preview,
911 CLUTTER_BIN_ALIGNMENT_END,
912 CLUTTER_BIN_ALIGNMENT_END);
915 g_warn_if_reached ();
918 g_settings_set_enum (self->priv->settings, "camera-position", pos);
922 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
925 ClutterActor *rectangle;
927 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
929 empathy_rounded_rectangle_set_border_width (
930 EMPATHY_ROUNDED_RECTANGLE (rectangle), 5);
931 empathy_rounded_rectangle_set_border_color (
932 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Red);
936 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
937 ClutterActor *rectangle)
939 empathy_rounded_rectangle_set_border_width (
940 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
941 empathy_rounded_rectangle_set_border_color (
942 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Black);
946 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
948 ClutterActor *rectangle;
950 rectangle = empathy_call_window_get_preview_rectangle (self,
951 self->priv->preview_pos);
953 /* We don't want to darken the rectangle where the preview
956 if (self->priv->preview_rectangle1 != rectangle)
957 empathy_call_window_darken_preview_rectangle (self,
958 self->priv->preview_rectangle1);
960 if (self->priv->preview_rectangle2 != rectangle)
961 empathy_call_window_darken_preview_rectangle (self,
962 self->priv->preview_rectangle2);
964 if (self->priv->preview_rectangle3 != rectangle)
965 empathy_call_window_darken_preview_rectangle (self,
966 self->priv->preview_rectangle3);
968 if (self->priv->preview_rectangle4 != rectangle)
969 empathy_call_window_darken_preview_rectangle (self,
970 self->priv->preview_rectangle4);
974 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
978 ClutterModifierType modifiers,
979 EmpathyCallWindow *self)
981 ClutterActor *stage = clutter_actor_get_stage (actor);
984 self->priv->drag_preview = clutter_clone_new (actor);
986 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
987 self->priv->drag_preview);
989 clutter_actor_transform_stage_point (actor, event_x, event_y,
992 clutter_actor_set_position (self->priv->drag_preview,
993 event_x - rel_x, event_y - rel_y);
995 clutter_drag_action_set_drag_handle (action,
996 self->priv->drag_preview);
998 clutter_actor_set_opacity (actor, 0);
999 clutter_actor_hide (self->priv->preview_shown_button);
1001 empathy_call_window_show_preview_rectangles (self, TRUE);
1002 empathy_call_window_darken_preview_rectangles (self);
1006 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
1007 ClutterActor *actor)
1009 clutter_actor_set_opacity (actor, 255);
1013 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
1014 ClutterActor *actor,
1017 ClutterModifierType modifiers,
1018 EmpathyCallWindow *self)
1020 PreviewPosition pos;
1023 /* Get the position before destroying the drag actor, otherwise the
1024 * preview_box allocation won't be valid and we won't be able to
1025 * calculate the position. */
1026 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1028 empathy_call_window_get_preview_coordinates (self,
1029 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
1032 /* Move the preview to the destination and destroy it afterwards */
1033 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
1036 "signal-swapped-after::completed",
1037 clutter_actor_destroy, self->priv->drag_preview,
1038 "signal-swapped-after::completed",
1039 clutter_actor_show, self->priv->preview_shown_button,
1040 "signal::completed",
1041 empathy_call_window_on_animation_completed_cb, actor,
1044 self->priv->drag_preview = NULL;
1046 if (pos != PREVIEW_POS_NONE)
1047 empathy_call_window_move_video_preview (self, pos);
1049 empathy_call_window_show_preview_rectangles (self, FALSE);
1053 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1054 ClutterActor *actor,
1057 EmpathyCallWindow *self)
1059 PreviewPosition pos;
1060 gfloat event_x, event_y;
1062 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1064 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1066 if (pos != PREVIEW_POS_NONE)
1067 empathy_call_window_highlight_preview_rectangle (self, pos);
1069 empathy_call_window_darken_preview_rectangles (self);
1073 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1074 ClutterCrossingEvent *event,
1075 EmpathyCallWindow *self)
1077 ClutterActor *rectangle;
1079 rectangle = empathy_call_window_get_preview_rectangle (self,
1080 self->priv->preview_pos);
1082 empathy_call_window_highlight_preview_rectangle (self,
1083 self->priv->preview_pos);
1085 clutter_actor_show (rectangle);
1091 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1092 ClutterCrossingEvent *event,
1093 EmpathyCallWindow *self)
1095 ClutterActor *rectangle;
1097 rectangle = empathy_call_window_get_preview_rectangle (self,
1098 self->priv->preview_pos);
1100 empathy_call_window_darken_preview_rectangle (self, rectangle);
1102 clutter_actor_hide (rectangle);
1108 create_video_preview (EmpathyCallWindow *self)
1110 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1111 ClutterLayoutManager *layout, *layout_center, *layout_end;
1112 ClutterActor *preview;
1115 ClutterAction *action;
1117 PreviewPosition pos;
1118 GdkRGBA transparent = { 0., 0., 0., 0. };
1120 g_assert (priv->video_preview == NULL);
1122 pos = g_settings_get_enum (priv->settings, "camera-position");
1124 preview = empathy_rounded_texture_new ();
1125 clutter_actor_set_size (preview,
1126 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1127 priv->video_preview_sink = clutter_gst_video_sink_new (
1128 CLUTTER_TEXTURE (preview));
1130 /* Add a little offset to the video preview */
1131 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1132 CLUTTER_BIN_ALIGNMENT_START);
1133 priv->video_preview = clutter_box_new (layout);
1134 clutter_actor_set_size (priv->video_preview,
1135 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1136 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1137 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1139 /* Spinner for when changing the camera device */
1140 priv->preview_spinner_widget = gtk_spinner_new ();
1141 priv->preview_spinner_actor = empathy_rounded_actor_new ();
1142 empathy_rounded_actor_set_round_factor (
1143 EMPATHY_ROUNDED_ACTOR (priv->preview_spinner_actor), 16);
1145 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1146 gtk_widget_override_background_color (
1147 gtk_clutter_actor_get_widget (
1148 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor)),
1149 GTK_STATE_FLAG_NORMAL, &transparent);
1150 gtk_widget_show (priv->preview_spinner_widget);
1153 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1154 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1155 priv->preview_spinner_widget);
1156 clutter_actor_set_size (priv->preview_spinner_actor,
1157 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1158 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1159 clutter_actor_hide (priv->preview_spinner_actor);
1161 /* We have a box with the margins and the video in the middle inside
1162 * a bigger box with an extra bottom margin so we're not on top of
1163 * the floating toolbar. */
1164 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1165 CLUTTER_BIN_ALIGNMENT_CENTER);
1166 box = clutter_box_new (layout_center);
1167 clutter_actor_set_size (box,
1168 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1169 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1171 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1172 clutter_container_add_actor (CLUTTER_CONTAINER (box),
1173 priv->preview_spinner_actor);
1174 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1176 g_object_set (priv->video_preview_sink,
1181 /* Translators: this is an "Info" label. It should be as short
1183 button = gtk_button_new_with_label (_("i"));
1184 priv->preview_shown_button = b = empathy_rounded_actor_new ();
1186 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1188 clutter_actor_set_size (b, 24, 24);
1190 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1191 CLUTTER_BIN_ALIGNMENT_END);
1192 box = clutter_box_new (layout_end);
1193 clutter_actor_set_size (box,
1194 SELF_VIDEO_SECTION_WIDTH,
1195 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1197 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1198 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1200 g_signal_connect (button, "clicked",
1201 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1204 /* Translators: this is an "Info" label. It should be as short
1206 button = gtk_button_new_with_label (_("i"));
1207 b = empathy_rounded_actor_new ();
1209 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1211 clutter_actor_set_size (b, 24, 24);
1212 priv->preview_hidden_button = b;
1214 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1215 priv->preview_hidden_button,
1216 CLUTTER_BIN_ALIGNMENT_START,
1217 CLUTTER_BIN_ALIGNMENT_END);
1219 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1221 clutter_actor_hide (priv->preview_hidden_button);
1223 g_signal_connect (button, "clicked",
1224 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1227 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1228 priv->video_preview,
1229 CLUTTER_BIN_ALIGNMENT_START,
1230 CLUTTER_BIN_ALIGNMENT_END);
1232 empathy_call_window_move_video_preview (self, pos);
1234 action = clutter_drag_action_new ();
1235 g_signal_connect (action, "drag-begin",
1236 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1237 g_signal_connect (action, "drag-end",
1238 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1239 g_signal_connect (action, "drag-motion",
1240 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1242 g_signal_connect (preview, "enter-event",
1243 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1244 g_signal_connect (preview, "leave-event",
1245 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1247 clutter_actor_add_action (preview, action);
1248 clutter_actor_set_reactive (preview, TRUE);
1249 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1253 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1255 clutter_actor_show (self->priv->preview_spinner_actor);
1256 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1260 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1262 clutter_actor_hide (self->priv->preview_spinner_actor);
1263 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1267 empathy_call_window_play_camera (EmpathyCallWindow *self,
1270 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1271 GstElement *preview;
1274 if (priv->video_preview == NULL)
1276 create_video_preview (self);
1277 add_video_preview_to_pipeline (self);
1282 state = GST_STATE_PLAYING;
1286 empathy_call_window_start_camera_spinning (self);
1287 state = GST_STATE_NULL;
1290 preview = priv->video_preview_sink;
1292 gst_element_set_state (preview, state);
1293 gst_element_set_state (priv->video_input, state);
1294 gst_element_set_state (priv->video_tee, state);
1298 display_video_preview (EmpathyCallWindow *self,
1301 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1305 /* Display the video preview */
1306 DEBUG ("Show video preview");
1308 empathy_call_window_play_camera (self, TRUE);
1309 clutter_actor_show (priv->video_preview);
1310 clutter_actor_raise_top (priv->floating_toolbar);
1314 /* Hide the video preview */
1315 DEBUG ("Hide video preview");
1317 if (priv->video_preview != NULL)
1319 clutter_actor_hide (priv->video_preview);
1320 empathy_call_window_play_camera (self, FALSE);
1326 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1328 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1330 empathy_call_window_status_message (window, _("Connecting…"));
1331 priv->call_state = CONNECTING;
1333 /* Show the toolbar */
1334 clutter_state_set_state (priv->transitions, "fade-in");
1337 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1338 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1342 disable_camera (EmpathyCallWindow *self)
1344 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1346 if (priv->camera_state == CAMERA_STATE_OFF)
1349 DEBUG ("Disable camera");
1351 display_video_preview (self, FALSE);
1353 if (priv->camera_state == CAMERA_STATE_ON)
1354 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1356 priv->camera_state = CAMERA_STATE_OFF;
1360 enable_camera (EmpathyCallWindow *self)
1362 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1364 if (priv->camera_state == CAMERA_STATE_ON)
1367 if (priv->video_input == NULL)
1369 DEBUG ("Can't enable camera, no input");
1373 DEBUG ("Enable camera");
1375 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1377 priv->camera_state = CAMERA_STATE_ON;
1381 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1382 EmpathyCallWindow *self)
1384 if (gtk_toggle_tool_button_get_active (toggle))
1385 enable_camera (self);
1387 disable_camera (self);
1391 create_pipeline (EmpathyCallWindow *self)
1393 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1396 g_assert (priv->pipeline == NULL);
1398 priv->pipeline = gst_pipeline_new (NULL);
1399 priv->pipeline_playing = FALSE;
1401 priv->video_tee = gst_element_factory_make ("tee", NULL);
1402 gst_object_ref (priv->video_tee);
1403 gst_object_sink (priv->video_tee);
1405 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1407 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1408 priv->bus_message_source_id = gst_bus_add_watch (bus,
1409 empathy_call_window_bus_message, self);
1411 g_object_unref (bus);
1415 empathy_call_window_settings_cb (GtkAction *action,
1416 EmpathyCallWindow *self)
1418 gchar *args = g_strdup_printf ("-p %s",
1419 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1421 empathy_launch_program (BIN_DIR, "empathy", args);
1427 empathy_call_window_contents_cb (GtkAction *action,
1428 EmpathyCallWindow *self)
1430 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1434 empathy_call_window_debug_cb (GtkAction *action,
1435 EmpathyCallWindow *self)
1437 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1441 empathy_call_window_about_cb (GtkAction *action,
1442 EmpathyCallWindow *self)
1444 empathy_about_dialog_new (GTK_WINDOW (self));
1448 empathy_call_window_toolbar_timeout (gpointer data)
1450 EmpathyCallWindow *self = data;
1452 /* We don't want to hide the toolbar if we're not in a call, as
1453 * to show the call status all the time. */
1454 if (self->priv->call_state != CONNECTING &&
1455 self->priv->call_state != DISCONNECTED)
1456 clutter_state_set_state (self->priv->transitions, "fade-out");
1462 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1464 EmpathyCallWindow *self)
1466 clutter_state_set_state (self->priv->transitions, "fade-in");
1468 if (self->priv->inactivity_src > 0)
1469 g_source_remove (self->priv->inactivity_src);
1471 self->priv->inactivity_src = g_timeout_add_seconds (3,
1472 empathy_call_window_toolbar_timeout, self);
1478 empathy_call_window_configure_event_cb (GtkWidget *widget,
1480 EmpathyCallWindow *self)
1482 GdkWindow *gdk_window;
1483 GdkWindowState window_state;
1485 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1486 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1488 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1489 &self->priv->dialpad_width, NULL);
1491 gdk_window = gtk_widget_get_window (widget);
1492 window_state = gdk_window_get_state (gdk_window);
1493 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1499 empathy_call_window_destroyed_cb (GtkWidget *object,
1500 EmpathyCallWindow *self)
1502 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1504 /* Save the geometry as if the dialpad was hidden. */
1505 empathy_geometry_save_values (GTK_WINDOW (self),
1506 self->priv->x, self->priv->y,
1507 self->priv->w - self->priv->dialpad_width, self->priv->h,
1508 self->priv->maximized);
1513 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1515 ClutterBindConstraint *constraint)
1517 ClutterActorBox allocation;
1519 clutter_actor_get_allocation_box (stage, &allocation);
1521 clutter_bind_constraint_set_offset (constraint,
1522 allocation.y2 - allocation.y1 -
1523 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1527 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1529 EmpathyCallWindow *self)
1531 switch (response_id)
1533 case GTK_RESPONSE_ACCEPT:
1534 tp_channel_dispatch_operation_handle_with_async (
1535 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1537 tp_clear_object (&self->priv->pending_cdo);
1538 tp_clear_object (&self->priv->pending_channel);
1539 tp_clear_object (&self->priv->pending_context);
1542 case GTK_RESPONSE_CANCEL:
1543 tp_channel_dispatch_operation_close_channels_async (
1544 self->priv->pending_cdo, NULL, NULL);
1546 empathy_call_window_status_message (self, _("Disconnected"));
1547 self->priv->call_state = DISCONNECTED;
1550 g_warn_if_reached ();
1555 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1559 g_assert (self->priv->call_state != CONNECTED);
1561 video = tpy_call_channel_has_initial_video (self->priv->pending_channel);
1563 empathy_call_window_status_message (self, _("Incoming call"));
1564 self->priv->call_state = RINGING;
1566 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1567 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1568 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1569 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1570 empathy_contact_get_alias (self->priv->contact));
1572 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1573 _("Reject"), GTK_RESPONSE_CANCEL,
1574 _("Answer"), GTK_RESPONSE_ACCEPT,
1577 g_signal_connect (self->priv->incoming_call_dialog, "response",
1578 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1579 gtk_widget_show (self->priv->incoming_call_dialog);
1583 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1587 EmpathyCallWindow *self)
1589 tp_clear_object (&self->priv->pending_cdo);
1590 tp_clear_object (&self->priv->pending_channel);
1591 tp_clear_object (&self->priv->pending_context);
1593 /* We don't know if the incoming call has been accepted or not, so we
1594 * assume it hasn't and if it has, we'll set the proper status when
1595 * we get the new handler. */
1596 empathy_call_window_status_message (self, _("Disconnected"));
1597 self->priv->call_state = DISCONNECTED;
1599 gtk_widget_destroy (self->priv->incoming_call_dialog);
1600 self->priv->incoming_call_dialog = NULL;
1604 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1605 TpyCallChannel *channel,
1606 TpChannelDispatchOperation *dispatch_operation,
1607 TpAddDispatchOperationContext *context)
1609 g_assert (self->priv->pending_channel == NULL);
1610 g_assert (self->priv->pending_context == NULL);
1611 g_assert (self->priv->pending_cdo == NULL);
1613 /* Start ringing and delay until the user answers or hangs. */
1614 self->priv->pending_channel = g_object_ref (channel);
1615 self->priv->pending_context = g_object_ref (context);
1616 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1618 g_signal_connect (self->priv->pending_cdo, "invalidated",
1619 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1621 empathy_call_window_set_state_ringing (self);
1622 tp_add_dispatch_operation_context_accept (context);
1626 empathy_call_window_init (EmpathyCallWindow *self)
1628 EmpathyCallWindowPriv *priv;
1630 GtkWidget *top_vbox;
1632 ClutterConstraint *constraint;
1633 ClutterActor *remote_avatar;
1634 GtkStyleContext *context;
1638 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1639 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1641 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1643 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1644 gui = empathy_builder_get_file (filename,
1645 "call_window_vbox", &top_vbox,
1646 "errors_vbox", &priv->errors_vbox,
1647 "pane", &priv->pane,
1648 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1649 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1650 "status_label", &priv->status_label,
1651 "audiocall", &priv->audio_call_button,
1652 "videocall", &priv->video_call_button,
1653 "microphone", &priv->mic_button,
1654 "camera", &priv->camera_button,
1655 "hangup", &priv->hangup_button,
1656 "dialpad", &priv->dialpad_button,
1657 "toolbar", &priv->toolbar,
1658 "bottom_toolbar", &priv->bottom_toolbar,
1659 "ui_manager", &priv->ui_manager,
1660 "menufullscreen", &priv->menu_fullscreen,
1661 "menupreviewswap", &priv->menu_swap_camera,
1662 "details_vbox", &priv->details_vbox,
1663 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1664 "acodec_encoding_label", &priv->acodec_encoding_label,
1665 "acodec_decoding_label", &priv->acodec_decoding_label,
1666 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1667 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1668 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1669 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1670 "video_local_candidate_label", &priv->video_local_candidate_label,
1671 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1672 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1673 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1674 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1678 empathy_builder_connect (gui, self,
1679 "hangup", "clicked", empathy_call_window_hangup_cb,
1680 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1681 "videocall", "clicked", empathy_call_window_video_call_cb,
1682 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1683 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1684 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1685 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1686 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1687 "menusettings", "activate", empathy_call_window_settings_cb,
1688 "menucontents", "activate", empathy_call_window_contents_cb,
1689 "menudebug", "activate", empathy_call_window_debug_cb,
1690 "menuabout", "activate", empathy_call_window_about_cb,
1691 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1692 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1693 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1694 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1697 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1699 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1701 g_object_bind_property (priv->camera_monitor, "available",
1702 priv->camera_button, "sensitive",
1703 G_BINDING_SYNC_CREATE);
1705 g_signal_connect (priv->camera_monitor, "added",
1706 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1707 g_signal_connect (priv->camera_monitor, "removed",
1708 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1710 priv->lock = g_mutex_new ();
1712 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1714 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1715 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1716 CONTENT_HBOX_BORDER_WIDTH);
1717 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1720 /* avatar/video box */
1721 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1722 CLUTTER_BIN_ALIGNMENT_CENTER);
1724 priv->video_box = clutter_box_new (priv->video_layout);
1726 priv->video_container = gtk_clutter_embed_new ();
1728 /* Set the background color to that of the rest of the window */
1729 context = gtk_widget_get_style_context (priv->content_hbox);
1730 gtk_style_context_get_background_color (context,
1731 GTK_STATE_FLAG_NORMAL, &rgba);
1732 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1733 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1734 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1735 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1736 clutter_stage_set_color (
1737 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1738 GTK_CLUTTER_EMBED (priv->video_container))),
1741 clutter_container_add (
1742 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1743 GTK_CLUTTER_EMBED (priv->video_container))),
1747 constraint = clutter_bind_constraint_new (
1748 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1749 CLUTTER_BIND_SIZE, 0);
1750 clutter_actor_add_constraint (priv->video_box, constraint);
1752 priv->remote_user_avatar_widget = gtk_image_new ();
1753 remote_avatar = gtk_clutter_actor_new_with_contents (
1754 priv->remote_user_avatar_widget);
1756 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1759 empathy_call_window_create_preview_rectangles (self);
1761 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1762 priv->video_container, TRUE, TRUE,
1763 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1765 create_pipeline (self);
1766 create_video_output_widget (self);
1767 create_audio_input (self);
1768 create_video_input (self);
1770 priv->floating_toolbar = empathy_rounded_actor_new ();
1772 gtk_widget_reparent (priv->bottom_toolbar,
1773 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1775 constraint = clutter_bind_constraint_new (
1776 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1779 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1782 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1783 "notify::allocation",
1784 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1787 clutter_actor_set_size (priv->floating_toolbar,
1788 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1789 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1791 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1792 priv->floating_toolbar,
1793 CLUTTER_BIN_ALIGNMENT_CENTER,
1794 CLUTTER_BIN_ALIGNMENT_END);
1796 clutter_actor_raise_top (priv->floating_toolbar);
1798 /* Transitions for the floating toolbar */
1799 priv->transitions = clutter_state_new ();
1801 /* all transitions last for 2s */
1802 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1804 /* transition from any state to "fade-out" state */
1805 clutter_state_set (priv->transitions, NULL, "fade-out",
1806 priv->floating_toolbar,
1807 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1810 /* transition from any state to "fade-in" state */
1811 clutter_state_set (priv->transitions, NULL, "fade-in",
1812 priv->floating_toolbar,
1813 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1816 /* put the actor into the "fade-in" state with no animation */
1817 clutter_state_warp_to_state (priv->transitions, "fade-in");
1819 /* The call will be started as soon the pipeline is playing */
1820 priv->start_call_when_playing = TRUE;
1822 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1823 G_CALLBACK (dtmf_button_pressed_cb),
1824 G_CALLBACK (dtmf_button_released_cb));
1826 priv->tones = g_string_new ("");
1828 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1831 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1834 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1836 gtk_widget_show_all (top_vbox);
1838 gtk_widget_hide (priv->dtmf_panel);
1839 gtk_widget_hide (priv->details_vbox);
1841 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1843 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1844 priv->video_container);
1846 /* We hide the bottom toolbar after 3s of inactivity and show it
1847 * again on mouse movement */
1848 priv->inactivity_src = g_timeout_add_seconds (3,
1849 empathy_call_window_toolbar_timeout, self);
1851 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1852 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1854 g_signal_connect (G_OBJECT (self), "realize",
1855 G_CALLBACK (empathy_call_window_realized_cb), self);
1857 g_signal_connect (G_OBJECT (self), "delete-event",
1858 G_CALLBACK (empathy_call_window_delete_cb), self);
1860 g_signal_connect (G_OBJECT (self), "window-state-event",
1861 G_CALLBACK (empathy_call_window_state_event_cb), self);
1863 g_signal_connect (G_OBJECT (self), "key-press-event",
1864 G_CALLBACK (empathy_call_window_key_press_cb), self);
1866 g_signal_connect (self, "motion-notify-event",
1867 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1869 priv->timer = g_timer_new ();
1871 g_object_ref (priv->ui_manager);
1872 g_object_unref (gui);
1874 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1875 priv->mic_menu = empathy_mic_menu_new (self);
1876 priv->camera_menu = empathy_camera_menu_new (self);
1878 empathy_call_window_show_hangup_button (self, TRUE);
1880 /* Retrieve initial volume */
1881 priv->volume = g_settings_get_double (priv->settings,
1882 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1884 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1885 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1887 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1888 /* These signals are used to track the window position and save it
1889 * when the window is destroyed. We need to do this as we don't want
1890 * the window geometry to be saved with the dialpad taken into account. */
1891 g_signal_connect (self, "destroy",
1892 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1893 g_signal_connect (self, "configure-event",
1894 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1895 g_signal_connect (self, "window-state-event",
1896 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1898 /* Don't display labels in both toolbars */
1899 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1902 /* Instead of specifying a width and a height, we specify only one size. That's
1903 because we want a square avatar icon. */
1905 init_contact_avatar_with_size (EmpathyContact *contact,
1906 GtkWidget *image_widget,
1909 GdkPixbuf *pixbuf_avatar = NULL;
1911 if (contact != NULL)
1913 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1917 if (pixbuf_avatar == NULL)
1919 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1920 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1923 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1925 if (pixbuf_avatar != NULL)
1926 g_object_unref (pixbuf_avatar);
1930 set_window_title (EmpathyCallWindow *self)
1932 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1935 if (priv->contact != NULL)
1937 /* translators: Call is a noun and %s is the contact name. This string
1938 * is used in the window title */
1939 tmp = g_strdup_printf (_("Call with %s"),
1940 empathy_contact_get_alias (priv->contact));
1941 gtk_window_set_title (GTK_WINDOW (self), tmp);
1946 g_warning ("Unknown remote contact!");
1951 set_remote_user_name (EmpathyCallWindow *self,
1952 EmpathyContact *contact)
1954 const gchar *alias = empathy_contact_get_alias (contact);
1955 const gchar *status = empathy_contact_get_status (contact);
1958 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1959 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1965 contact_name_changed_cb (EmpathyContact *contact,
1967 EmpathyCallWindow *self)
1969 set_window_title (self);
1970 set_remote_user_name (self, contact);
1974 contact_presence_changed_cb (EmpathyContact *contact,
1976 EmpathyCallWindow *self)
1978 set_remote_user_name (self, contact);
1982 contact_avatar_changed_cb (EmpathyContact *contact,
1984 EmpathyCallWindow *self)
1987 GtkAllocation allocation;
1988 GtkWidget *avatar_widget;
1990 avatar_widget = self->priv->remote_user_avatar_widget;
1992 gtk_widget_get_allocation (avatar_widget, &allocation);
1993 size = allocation.height;
1997 /* the widget is not allocated yet, set a default size */
1998 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1999 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
2002 init_contact_avatar_with_size (contact, avatar_widget, size);
2004 avatar_widget = self->priv->remote_user_avatar_toolbar;
2006 gtk_widget_get_allocation (avatar_widget, &allocation);
2007 size = allocation.height;
2011 /* the widget is not allocated yet, set a default size */
2012 size = SMALL_TOOLBAR_SIZE;
2015 init_contact_avatar_with_size (contact, avatar_widget, size);
2019 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2020 EmpathyCallHandler *handler)
2022 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2024 tp_g_signal_connect_object (priv->contact, "notify::name",
2025 G_CALLBACK (contact_name_changed_cb), self, 0);
2026 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2027 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2028 tp_g_signal_connect_object (priv->contact, "notify::presence",
2029 G_CALLBACK (contact_presence_changed_cb), self, 0);
2031 set_window_title (self);
2032 set_remote_user_name (self, priv->contact);
2034 init_contact_avatar_with_size (priv->contact,
2035 priv->remote_user_avatar_widget,
2036 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2037 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2039 init_contact_avatar_with_size (priv->contact,
2040 priv->remote_user_avatar_toolbar,
2041 SMALL_TOOLBAR_SIZE);
2043 /* The remote avatar is shown by default and will be hidden when we receive
2044 video from the remote side. */
2045 clutter_actor_hide (priv->video_output);
2046 gtk_widget_show (priv->remote_user_avatar_widget);
2050 update_send_codec (EmpathyCallWindow *self,
2053 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2060 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2061 widget = priv->acodec_encoding_label;
2065 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2066 widget = priv->vcodec_encoding_label;
2072 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2073 gtk_label_set_text (GTK_LABEL (widget), tmp);
2078 send_audio_codec_notify_cb (GObject *object,
2082 EmpathyCallWindow *self = user_data;
2084 update_send_codec (self, TRUE);
2088 send_video_codec_notify_cb (GObject *object,
2092 EmpathyCallWindow *self = user_data;
2094 update_send_codec (self, FALSE);
2098 update_recv_codec (EmpathyCallWindow *self,
2101 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2104 GString *str = NULL;
2108 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2109 widget = priv->acodec_decoding_label;
2113 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2114 widget = priv->vcodec_decoding_label;
2120 for (l = codecs; l != NULL; l = g_list_next (l))
2122 FsCodec *codec = l->data;
2125 str = g_string_new (NULL);
2127 g_string_append (str, ", ");
2129 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2133 gtk_label_set_text (GTK_LABEL (widget), str->str);
2134 g_string_free (str, TRUE);
2138 recv_audio_codecs_notify_cb (GObject *object,
2142 EmpathyCallWindow *self = user_data;
2144 update_recv_codec (self, TRUE);
2148 recv_video_codecs_notify_cb (GObject *object,
2152 EmpathyCallWindow *self = user_data;
2154 update_recv_codec (self, FALSE);
2157 static const gchar *
2158 candidate_type_to_str (FsCandidate *candidate)
2160 switch (candidate->type)
2162 case FS_CANDIDATE_TYPE_HOST:
2164 case FS_CANDIDATE_TYPE_SRFLX:
2165 return "server reflexive";
2166 case FS_CANDIDATE_TYPE_PRFLX:
2167 return "peer reflexive";
2168 case FS_CANDIDATE_TYPE_RELAY:
2170 case FS_CANDIDATE_TYPE_MULTICAST:
2177 static const gchar *
2178 candidate_type_to_desc (FsCandidate *candidate)
2180 switch (candidate->type)
2182 case FS_CANDIDATE_TYPE_HOST:
2183 return _("The IP address as seen by the machine");
2184 case FS_CANDIDATE_TYPE_SRFLX:
2185 return _("The IP address as seen by a server on the Internet");
2186 case FS_CANDIDATE_TYPE_PRFLX:
2187 return _("The IP address of the peer as seen by the other side");
2188 case FS_CANDIDATE_TYPE_RELAY:
2189 return _("The IP address of a relay server");
2190 case FS_CANDIDATE_TYPE_MULTICAST:
2191 return _("The IP address of the multicast group");
2198 update_candidat_widget (EmpathyCallWindow *self,
2201 FsCandidate *candidate)
2205 g_assert (candidate != NULL);
2206 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2207 candidate->port, candidate_type_to_str (candidate));
2209 gtk_label_set_text (GTK_LABEL (label), str);
2210 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2216 candidates_changed_cb (GObject *object,
2218 EmpathyCallWindow *self)
2220 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2221 FsCandidate *candidate = NULL;
2223 if (type == FS_MEDIA_TYPE_VIDEO)
2225 /* Update remote candidate */
2226 candidate = empathy_call_handler_get_video_remote_candidate (
2229 update_candidat_widget (self, priv->video_remote_candidate_label,
2230 priv->video_remote_candidate_info_img, candidate);
2232 /* Update local candidate */
2233 candidate = empathy_call_handler_get_video_local_candidate (
2236 update_candidat_widget (self, priv->video_local_candidate_label,
2237 priv->video_local_candidate_info_img, candidate);
2241 /* Update remote candidate */
2242 candidate = empathy_call_handler_get_audio_remote_candidate (
2245 update_candidat_widget (self, priv->audio_remote_candidate_label,
2246 priv->audio_remote_candidate_info_img, candidate);
2248 /* Update local candidate */
2249 candidate = empathy_call_handler_get_audio_local_candidate (
2252 update_candidat_widget (self, priv->audio_local_candidate_label,
2253 priv->audio_local_candidate_info_img, candidate);
2258 empathy_call_window_constructed (GObject *object)
2260 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2261 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2262 TpyCallChannel *call;
2265 g_assert (priv->handler != NULL);
2267 g_object_get (priv->handler, "call-channel", &call, NULL);
2268 state = tpy_call_channel_get_state (call, NULL, NULL);
2269 priv->outgoing = (state == TPY_CALL_STATE_PENDING_INITIATOR);
2270 tp_clear_object (&call);
2272 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2273 g_assert (priv->contact != NULL);
2275 if (!empathy_contact_can_voip_video (priv->contact))
2277 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2278 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2281 empathy_call_window_setup_avatars (self, priv->handler);
2282 empathy_call_window_set_state_connecting (self);
2284 if (!empathy_call_handler_has_initial_video (priv->handler))
2286 gtk_toggle_tool_button_set_active (
2287 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2289 /* If call has InitialVideo, the preview will be started once the call has
2290 * been started (start_call()). */
2292 update_send_codec (self, TRUE);
2293 update_send_codec (self, FALSE);
2294 update_recv_codec (self, TRUE);
2295 update_recv_codec (self, FALSE);
2297 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2298 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2299 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2300 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2301 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2302 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2303 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2304 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2306 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2307 G_CALLBACK (candidates_changed_cb), self, 0);
2310 static void empathy_call_window_dispose (GObject *object);
2311 static void empathy_call_window_finalize (GObject *object);
2314 empathy_call_window_set_property (GObject *object,
2315 guint property_id, const GValue *value, GParamSpec *pspec)
2317 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2319 switch (property_id)
2321 case PROP_CALL_HANDLER:
2322 priv->handler = g_value_dup_object (value);
2325 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2330 empathy_call_window_get_property (GObject *object,
2331 guint property_id, GValue *value, GParamSpec *pspec)
2333 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2335 switch (property_id)
2337 case PROP_CALL_HANDLER:
2338 g_value_set_object (value, priv->handler);
2341 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2346 empathy_call_window_class_init (
2347 EmpathyCallWindowClass *empathy_call_window_class)
2349 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2350 GParamSpec *param_spec;
2352 g_type_class_add_private (empathy_call_window_class,
2353 sizeof (EmpathyCallWindowPriv));
2355 object_class->constructed = empathy_call_window_constructed;
2356 object_class->set_property = empathy_call_window_set_property;
2357 object_class->get_property = empathy_call_window_get_property;
2359 object_class->dispose = empathy_call_window_dispose;
2360 object_class->finalize = empathy_call_window_finalize;
2362 param_spec = g_param_spec_object ("handler",
2363 "handler", "The call handler",
2364 EMPATHY_TYPE_CALL_HANDLER,
2365 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2366 g_object_class_install_property (object_class,
2367 PROP_CALL_HANDLER, param_spec);
2371 empathy_call_window_dispose (GObject *object)
2373 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2374 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2376 if (priv->dispose_has_run)
2379 priv->dispose_has_run = TRUE;
2381 if (priv->handler != NULL)
2383 empathy_call_handler_stop_call (priv->handler);
2384 tp_clear_object (&priv->handler);
2387 if (priv->bus_message_source_id != 0)
2389 g_source_remove (priv->bus_message_source_id);
2390 priv->bus_message_source_id = 0;
2393 if (priv->got_video_src > 0)
2395 g_source_remove (priv->got_video_src);
2396 priv->got_video_src = 0;
2399 if (priv->inactivity_src > 0)
2401 g_source_remove (priv->inactivity_src);
2402 priv->inactivity_src = 0;
2405 tp_clear_object (&priv->pipeline);
2406 tp_clear_object (&priv->video_input);
2407 tp_clear_object (&priv->audio_input);
2408 tp_clear_object (&priv->video_tee);
2409 tp_clear_object (&priv->ui_manager);
2410 tp_clear_object (&priv->fullscreen);
2411 tp_clear_object (&priv->camera_monitor);
2412 tp_clear_object (&priv->settings);
2413 tp_clear_object (&priv->sound_mgr);
2414 tp_clear_object (&priv->mic_menu);
2415 tp_clear_object (&priv->camera_menu);
2417 g_list_free_full (priv->notifiers, g_object_unref);
2419 if (priv->timer_id != 0)
2420 g_source_remove (priv->timer_id);
2423 if (priv->contact != NULL)
2425 g_signal_handlers_disconnect_by_func (priv->contact,
2426 contact_name_changed_cb, self);
2427 priv->contact = NULL;
2430 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2434 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2436 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2438 if (priv->video_output_motion_handler_id != 0)
2440 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2441 priv->video_output_motion_handler_id);
2442 priv->video_output_motion_handler_id = 0;
2447 empathy_call_window_finalize (GObject *object)
2449 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2450 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2452 disconnect_video_output_motion_handler (self);
2454 /* free any data held directly by the object here */
2455 g_mutex_free (priv->lock);
2457 g_timer_destroy (priv->timer);
2459 g_string_free (priv->tones, TRUE);
2461 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2466 empathy_call_window_new (EmpathyCallHandler *handler)
2468 return EMPATHY_CALL_WINDOW (
2469 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2473 empathy_call_window_present (EmpathyCallWindow *self,
2474 EmpathyCallHandler *handler)
2476 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2478 tp_clear_object (&self->priv->handler);
2479 self->priv->handler = g_object_ref (handler);
2480 empathy_call_window_connect_handler (self);
2482 empathy_window_present (GTK_WINDOW (self));
2483 empathy_call_window_restart_call (self);
2487 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2488 GstElement *conference, gpointer user_data)
2490 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2491 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2492 FsElementAddedNotifier *notifier;
2495 DEBUG ("Conference added");
2497 /* Add notifier to set the various element properties as needed */
2498 notifier = fs_element_added_notifier_new ();
2499 keyfile = fs_utils_get_default_element_properties (conference);
2501 if (keyfile != NULL)
2502 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2504 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2506 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2508 gst_bin_add (GST_BIN (priv->pipeline), conference);
2509 gst_element_set_state (conference, GST_STATE_PLAYING);
2513 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2514 GstElement *conference, gpointer user_data)
2516 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2517 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2519 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2520 gst_element_set_state (conference, GST_STATE_NULL);
2524 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2526 GstStateChangeReturn state_change_return;
2527 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2529 if (priv->pipeline == NULL)
2532 if (priv->bus_message_source_id != 0)
2534 g_source_remove (priv->bus_message_source_id);
2535 priv->bus_message_source_id = 0;
2538 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2540 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2541 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2543 if (priv->pipeline != NULL)
2544 g_object_unref (priv->pipeline);
2545 priv->pipeline = NULL;
2547 if (priv->audio_output != NULL)
2548 g_object_unref (priv->audio_output);
2549 priv->audio_output = NULL;
2551 if (priv->video_tee != NULL)
2552 g_object_unref (priv->video_tee);
2553 priv->video_tee = NULL;
2555 if (priv->video_preview != NULL)
2556 clutter_actor_destroy (priv->video_preview);
2557 priv->video_preview = NULL;
2559 /* If we destroy the preview while it's being dragged, we won't
2560 * get the ::drag-end signal, so manually destroy the clone */
2561 if (priv->drag_preview != NULL)
2563 clutter_actor_destroy (priv->drag_preview);
2564 empathy_call_window_show_preview_rectangles (self, FALSE);
2565 priv->drag_preview = NULL;
2568 priv->funnel = NULL;
2570 create_pipeline (self);
2571 /* Call will be started when user will hit the 'redial' button */
2572 priv->start_call_when_playing = FALSE;
2573 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2579 g_message ("Error: could not destroy pipeline. Closing call window");
2580 gtk_widget_destroy (GTK_WIDGET (self));
2587 reset_details_pane (EmpathyCallWindow *self)
2589 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2591 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2592 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2593 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2594 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2598 empathy_call_window_disconnected (EmpathyCallWindow *self,
2601 gboolean could_disconnect = FALSE;
2602 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2603 gboolean could_reset_pipeline;
2605 /* Leave full screen mode if needed */
2606 gtk_window_unfullscreen (GTK_WINDOW (self));
2608 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2609 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2611 priv->sending_tones = FALSE;
2612 g_string_set_size (priv->tones, 0);
2614 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2616 if (priv->call_state == CONNECTING)
2617 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2619 if (priv->call_state != REDIALING)
2620 priv->call_state = DISCONNECTED;
2622 /* Show the toolbar */
2623 clutter_state_set_state (priv->transitions, "fade-in");
2625 if (could_reset_pipeline)
2627 g_mutex_lock (priv->lock);
2629 g_timer_stop (priv->timer);
2631 if (priv->timer_id != 0)
2632 g_source_remove (priv->timer_id);
2635 g_mutex_unlock (priv->lock);
2638 /* We are about to destroy the window, no need to update it or create
2639 * a video preview */
2642 empathy_call_window_status_message (self, _("Disconnected"));
2644 empathy_call_window_show_hangup_button (self, FALSE);
2646 /* Unsensitive the camera and mic button */
2647 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2648 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2650 /* Be sure that the mic button is enabled */
2651 gtk_toggle_tool_button_set_active (
2652 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2654 if (priv->camera_state == CAMERA_STATE_ON)
2656 /* Restart the preview with the new pipeline. */
2657 display_video_preview (self, TRUE);
2660 /* destroy the video output; it will be recreated when we'll redial */
2661 disconnect_video_output_motion_handler (self);
2662 if (priv->video_output != NULL)
2663 clutter_actor_destroy (priv->video_output);
2664 priv->video_output = NULL;
2665 if (priv->got_video_src > 0)
2667 g_source_remove (priv->got_video_src);
2668 priv->got_video_src = 0;
2671 gtk_widget_show (priv->remote_user_avatar_widget);
2673 reset_details_pane (self);
2675 priv->sending_video = FALSE;
2676 priv->call_started = FALSE;
2678 could_disconnect = TRUE;
2680 /* TODO: display the self avatar of the preview (depends if the "Always
2681 * Show Video Preview" is enabled or not) */
2684 return could_disconnect;
2689 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2692 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2693 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2695 if (empathy_call_window_disconnected (self, TRUE) &&
2696 priv->call_state == REDIALING)
2697 empathy_call_window_restart_call (self);
2701 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2703 FsMediaType media_type,
2704 EmpathyCallWindow *self)
2706 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2708 DEBUG ("removing content");
2711 * This assumes that there is only one video stream per channel...
2714 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2716 if (priv->funnel != NULL)
2720 output = priv->video_output_sink;
2722 gst_element_set_state (output, GST_STATE_NULL);
2723 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2725 gst_bin_remove (GST_BIN (priv->pipeline), output);
2726 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2727 priv->funnel = NULL;
2731 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2733 if (priv->audio_output != NULL)
2735 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2737 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2738 priv->audio_output = NULL;
2746 /* Called with global lock held */
2748 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2750 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2754 if (priv->funnel == NULL)
2756 output = priv->video_output_sink;
2758 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2762 g_warning ("Could not create fsfunnel");
2766 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2768 gst_object_unref (priv->funnel);
2769 priv->funnel = NULL;
2770 g_warning ("Could not add funnel to pipeline");
2774 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2776 g_warning ("Could not add the video output widget to the pipeline");
2780 if (!gst_element_link (priv->funnel, output))
2782 g_warning ("Could not link output sink to funnel");
2783 goto error_output_added;
2786 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2788 g_warning ("Could not start video sink");
2789 goto error_output_added;
2792 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2794 g_warning ("Could not start funnel");
2795 goto error_output_added;
2799 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2802 g_warning ("Could not get request pad from funnel");
2809 gst_element_set_locked_state (priv->funnel, TRUE);
2810 gst_element_set_locked_state (output, TRUE);
2812 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2813 gst_element_set_state (output, GST_STATE_NULL);
2815 gst_bin_remove (GST_BIN (priv->pipeline), output);
2816 gst_element_set_locked_state (output, FALSE);
2820 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2821 priv->funnel = NULL;
2826 /* Called with global lock held */
2828 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2830 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2832 GstPadTemplate *template;
2834 if (priv->audio_output == NULL)
2836 priv->audio_output = empathy_audio_sink_new ();
2837 g_object_ref_sink (priv->audio_output);
2839 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2841 g_warning ("Could not add audio sink to pipeline");
2842 g_object_unref (priv->audio_output);
2843 goto error_add_output;
2846 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2848 g_warning ("Could not start audio sink");
2853 template = gst_element_class_get_pad_template (
2854 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2856 pad = gst_element_request_pad (priv->audio_output,
2857 template, NULL, NULL);
2861 g_warning ("Could not get sink pad from sink");
2868 gst_element_set_locked_state (priv->audio_output, TRUE);
2869 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2870 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2871 priv->audio_output = NULL;
2879 empathy_call_window_update_timer (gpointer user_data)
2881 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2882 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2883 const gchar *status;
2887 time_ = g_timer_elapsed (priv->timer, NULL);
2889 if (priv->call_state == HELD)
2890 status = _("On hold");
2891 else if (!gtk_toggle_tool_button_get_active (
2892 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2895 status = _("Duration");
2897 /* Translators: 'status - minutes:seconds' the caller has been connected */
2898 str = g_strdup_printf (_("%s — %d:%02dm"),
2900 (int) time_ / 60, (int) time_ % 60);
2901 empathy_call_window_status_message (self, str);
2909 display_error (EmpathyCallWindow *self,
2910 TpyCallChannel *call,
2914 const gchar *details)
2916 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2917 GtkWidget *info_bar;
2918 GtkWidget *content_area;
2925 /* Create info bar */
2926 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2929 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2931 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2933 /* hbox containing the image and the messages vbox */
2934 hbox = gtk_hbox_new (FALSE, 3);
2935 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2938 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2939 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2941 /* vbox containing the main message and the details expander */
2942 vbox = gtk_vbox_new (FALSE, 3);
2943 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2946 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2948 label = gtk_label_new (NULL);
2949 gtk_label_set_markup (GTK_LABEL (label), txt);
2950 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2951 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2954 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2957 if (details != NULL)
2959 GtkWidget *expander;
2961 expander = gtk_expander_new (_("Technical Details"));
2963 txt = g_strdup_printf ("<i>%s</i>", details);
2965 label = gtk_label_new (NULL);
2966 gtk_label_set_markup (GTK_LABEL (label), txt);
2967 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2968 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2971 gtk_container_add (GTK_CONTAINER (expander), label);
2972 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2975 g_signal_connect (info_bar, "response",
2976 G_CALLBACK (gtk_widget_destroy), NULL);
2978 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2979 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2980 gtk_widget_show_all (info_bar);
2984 media_stream_error_to_txt (EmpathyCallWindow *self,
2985 TpyCallChannel *call,
2987 TpMediaStreamError error)
2989 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2990 const gchar *cm = NULL;
2996 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2998 return g_strdup_printf (
2999 _("%s's software does not understand any of the audio formats "
3000 "supported by your computer"),
3001 empathy_contact_get_alias (priv->contact));
3003 return g_strdup_printf (
3004 _("%s's software does not understand any of the video formats "
3005 "supported by your computer"),
3006 empathy_contact_get_alias (priv->contact));
3008 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3009 return g_strdup_printf (
3010 _("Can't establish a connection to %s. "
3011 "One of you might be on a network that does not allow "
3012 "direct connections."),
3013 empathy_contact_get_alias (priv->contact));
3015 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3016 return g_strdup (_("There was a failure on the network"));
3018 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3020 return g_strdup (_("The audio formats necessary for this call "
3021 "are not installed on your computer"));
3023 return g_strdup (_("The video formats necessary for this call "
3024 "are not installed on your computer"));
3026 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3027 tp_connection_parse_object_path (
3028 tp_channel_borrow_connection (TP_CHANNEL (call)),
3031 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3032 "product=Telepathy&component=%s", cm);
3034 result = g_strdup_printf (
3035 _("Something unexpected happened in a Telepathy component. "
3036 "Please <a href=\"%s\">report this bug</a> and attach "
3037 "logs gathered from the 'Debug' window in the Help menu."), url);
3043 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3044 return g_strdup (_("There was a failure in the call engine"));
3046 case TP_MEDIA_STREAM_ERROR_EOS:
3047 return g_strdup (_("The end of the stream was reached"));
3049 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3056 empathy_call_window_stream_error (EmpathyCallWindow *self,
3057 TpyCallChannel *call,
3066 desc = media_stream_error_to_txt (self, call, audio, code);
3069 /* No description, use the error message. That's not great as it's not
3070 * localized but it's better than nothing. */
3071 display_error (self, call, icon, title, msg, NULL);
3075 display_error (self, call, icon, title, desc, msg);
3081 empathy_call_window_audio_stream_error (TpyCallChannel *call,
3084 EmpathyCallWindow *self)
3086 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3087 "gnome-stock-mic", _("Can't establish audio stream"));
3091 empathy_call_window_video_stream_error (TpyCallChannel *call,
3094 EmpathyCallWindow *self)
3096 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3097 "camera-web", _("Can't establish video stream"));
3102 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3104 EmpathyCallWindow *self)
3106 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3107 TpyCallChannel *call;
3108 gboolean can_send_video;
3110 if (state != TPY_CALL_STATE_ACCEPTED)
3113 if (priv->call_state == CONNECTED)
3116 g_timer_start (priv->timer);
3117 priv->call_state = CONNECTED;
3119 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3121 can_send_video = priv->video_input != NULL &&
3122 empathy_contact_can_voip_video (priv->contact) &&
3123 empathy_camera_monitor_get_available (priv->camera_monitor);
3125 g_object_get (priv->handler, "call-channel", &call, NULL);
3127 if (tpy_call_channel_has_dtmf (call))
3128 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3130 if (priv->video_input == NULL)
3131 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3133 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3135 empathy_call_window_show_hangup_button (self, TRUE);
3137 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3139 clutter_actor_hide (priv->video_output);
3140 gtk_widget_show (priv->remote_user_avatar_widget);
3142 g_object_unref (call);
3144 g_mutex_lock (priv->lock);
3146 priv->timer_id = g_timeout_add_seconds (1,
3147 empathy_call_window_update_timer, self);
3149 g_mutex_unlock (priv->lock);
3151 empathy_call_window_update_timer (self);
3153 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3157 empathy_call_window_show_video_output_cb (gpointer user_data)
3159 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3161 if (self->priv->video_output != NULL)
3163 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3164 clutter_actor_show (self->priv->video_output);
3165 empathy_call_window_raise_actors (self);
3172 empathy_call_window_check_video_cb (gpointer data)
3174 EmpathyCallWindow *self = data;
3176 if (self->priv->got_video)
3178 self->priv->got_video = FALSE;
3182 /* No video in the last N seconds, display the remote avatar */
3183 empathy_call_window_show_video_output (self, FALSE);
3188 /* Called from the streaming thread */
3190 empathy_call_window_video_probe_cb (GstPad *pad,
3191 GstMiniObject *mini_obj,
3192 EmpathyCallWindow *self)
3195 if (GST_IS_EVENT (mini_obj))
3198 if (G_UNLIKELY (!self->priv->got_video))
3200 /* show the remote video */
3201 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3202 empathy_call_window_show_video_output_cb,
3203 g_object_ref (self), g_object_unref);
3205 self->priv->got_video = TRUE;
3211 /* Called from the streaming thread */
3213 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3214 GstPad *src, guint media_type, gpointer user_data)
3216 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3217 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3218 gboolean retval = FALSE;
3222 g_mutex_lock (priv->lock);
3226 case TP_MEDIA_STREAM_TYPE_AUDIO:
3227 pad = empathy_call_window_get_audio_sink_pad (self);
3229 case TP_MEDIA_STREAM_TYPE_VIDEO:
3230 g_idle_add (empathy_call_window_show_video_output_cb, self);
3231 pad = empathy_call_window_get_video_sink_pad (self);
3233 gst_pad_add_data_probe (src,
3234 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3235 if (priv->got_video_src > 0)
3236 g_source_remove (priv->got_video_src);
3237 priv->got_video_src = g_timeout_add_seconds (5,
3238 empathy_call_window_check_video_cb, self);
3241 g_assert_not_reached ();
3247 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3248 g_warning ("Could not link %s sink pad",
3249 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3253 gst_object_unref (pad);
3257 /* If no sink could be linked, try to add fakesink to prevent the whole call
3262 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3264 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3266 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3267 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3268 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3270 gst_element_set_locked_state (fakesink, TRUE);
3271 gst_element_set_state (fakesink, GST_STATE_NULL);
3272 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3276 DEBUG ("Could not link real sink, linked fakesink instead");
3278 gst_object_unref (sinkpad);
3282 gst_object_unref (fakesink);
3287 g_mutex_unlock (priv->lock);
3293 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
3294 GstPad *sink, FsMediaType media_type, gpointer user_data)
3296 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3297 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3299 gboolean retval = FALSE;
3303 case FS_MEDIA_TYPE_AUDIO:
3304 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3306 g_warning ("Could not add audio source to pipeline");
3310 pad = gst_element_get_static_pad (priv->audio_input, "src");
3313 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3314 g_warning ("Could not get source pad from audio source");
3318 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3320 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3321 g_warning ("Could not link audio source to farsight");
3325 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3327 g_warning ("Could not start audio source");
3328 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3329 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3335 case FS_MEDIA_TYPE_VIDEO:
3336 if (priv->video_tee != NULL)
3338 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3339 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3341 g_warning ("Could not link video source input pipeline");
3344 gst_object_unref (pad);
3350 g_assert_not_reached ();
3357 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3359 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3360 GstElement *preview;
3362 disable_camera (self);
3364 DEBUG ("remove video input");
3365 preview = priv->video_preview_sink;
3367 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3368 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3369 gst_element_set_state (preview, GST_STATE_NULL);
3371 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3374 g_object_unref (priv->video_input);
3375 priv->video_input = NULL;
3376 g_object_unref (priv->video_tee);
3377 priv->video_tee = NULL;
3378 clutter_actor_destroy (priv->video_preview);
3379 priv->video_preview = NULL;
3381 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3385 start_call (EmpathyCallWindow *self)
3387 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3389 priv->call_started = TRUE;
3390 empathy_call_handler_start_call (priv->handler,
3391 gtk_get_current_event_time ());
3393 if (empathy_call_handler_has_initial_video (priv->handler))
3395 TpyCallChannel *call;
3398 g_object_get (priv->handler, "call-channel", &call, NULL);
3399 s = tpy_call_channel_get_video_state (call);
3401 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3402 s == TPY_SENDING_STATE_SENDING)
3404 /* Enable 'send video' buttons and display the preview */
3405 gtk_toggle_tool_button_set_active (
3406 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3410 gtk_toggle_tool_button_set_active (
3411 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3413 if (priv->video_preview == NULL)
3415 create_video_preview (self);
3416 add_video_preview_to_pipeline (self);
3420 g_object_unref (call);
3425 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3428 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3429 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3430 GstState newstate, pending;
3432 empathy_call_handler_bus_message (priv->handler, bus, message);
3434 switch (GST_MESSAGE_TYPE (message))
3436 case GST_MESSAGE_STATE_CHANGED:
3437 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3439 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3441 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3442 !priv->call_started)
3444 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3445 if (newstate == GST_STATE_PAUSED)
3447 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3448 priv->pipeline_playing = TRUE;
3450 if (priv->start_call_when_playing)
3454 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3456 gst_message_parse_state_changed (message, NULL, &newstate,
3459 if (newstate == GST_STATE_PLAYING &&
3460 pending == GST_STATE_VOID_PENDING)
3461 empathy_call_window_stop_camera_spinning (self);
3464 case GST_MESSAGE_ERROR:
3466 GError *error = NULL;
3467 GstElement *gst_error;
3470 gst_message_parse_error (message, &error, &debug);
3471 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3473 g_message ("Element error: %s -- %s\n", error->message, debug);
3475 if (g_str_has_prefix (gst_element_get_name (gst_error),
3476 VIDEO_INPUT_ERROR_PREFIX))
3478 /* Remove the video input and continue */
3479 if (priv->video_input != NULL)
3480 empathy_call_window_remove_video_input (self);
3481 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3485 empathy_call_window_disconnected (self, TRUE);
3487 g_error_free (error);
3490 case GST_MESSAGE_UNKNOWN:
3491 case GST_MESSAGE_EOS:
3492 case GST_MESSAGE_WARNING:
3493 case GST_MESSAGE_INFO:
3494 case GST_MESSAGE_TAG:
3495 case GST_MESSAGE_BUFFERING:
3496 case GST_MESSAGE_STATE_DIRTY:
3497 case GST_MESSAGE_STEP_DONE:
3498 case GST_MESSAGE_CLOCK_PROVIDE:
3499 case GST_MESSAGE_CLOCK_LOST:
3500 case GST_MESSAGE_NEW_CLOCK:
3501 case GST_MESSAGE_STRUCTURE_CHANGE:
3502 case GST_MESSAGE_STREAM_STATUS:
3503 case GST_MESSAGE_APPLICATION:
3504 case GST_MESSAGE_ELEMENT:
3505 case GST_MESSAGE_SEGMENT_START:
3506 case GST_MESSAGE_SEGMENT_DONE:
3507 case GST_MESSAGE_DURATION:
3508 case GST_MESSAGE_ANY:
3517 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3518 GHashTable *members,
3519 EmpathyCallWindow *self)
3521 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3522 GHashTableIter iter;
3523 gpointer key, value;
3524 gboolean held = FALSE;
3526 g_hash_table_iter_init (&iter, members);
3527 while (g_hash_table_iter_next (&iter, &key, &value))
3529 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3531 /* This assumes this is a 1-1 call, otherwise one participant
3532 * putting the call on hold wouldn't mean the call is on hold
3540 priv->call_state = HELD;
3541 else if (priv->call_state == HELD)
3542 priv->call_state = CONNECTED;
3546 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3548 EmpathyCallWindow *self)
3550 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3551 TpyCallChannel *call;
3553 g_object_get (priv->handler, "call-channel", &call, NULL);
3558 tp_g_signal_connect_object (call, "audio-stream-error",
3559 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3560 tp_g_signal_connect_object (call, "video-stream-error",
3561 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3564 tp_g_signal_connect_object (call, "members-changed",
3565 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3567 tp_cli_channel_interface_dtmf_connect_to_stopped_tones (TP_CHANNEL (call),
3568 empathy_call_window_tones_stopped_cb, self, NULL,
3569 G_OBJECT (call), NULL);
3571 g_object_unref (call);
3575 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3577 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3578 TpyCallChannel *call;
3580 g_signal_connect (priv->handler, "state-changed",
3581 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3582 g_signal_connect (priv->handler, "conference-added",
3583 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3584 g_signal_connect (priv->handler, "conference-removed",
3585 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3586 g_signal_connect (priv->handler, "closed",
3587 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3588 g_signal_connect (priv->handler, "src-pad-added",
3589 G_CALLBACK (empathy_call_window_src_added_cb), self);
3590 g_signal_connect (priv->handler, "sink-pad-added",
3591 G_CALLBACK (empathy_call_window_sink_added_cb), self);
3592 g_signal_connect (priv->handler, "sink-pad-removed",
3593 G_CALLBACK (empathy_call_window_sink_removed_cb), self);
3595 /* We connect to ::call-channel unconditionally since we'll
3596 * get new channels if we hangup and redial or if we reuse the
3598 g_signal_connect (priv->handler, "notify::call-channel",
3599 G_CALLBACK (call_handler_notify_call_cb), self);
3601 g_object_get (priv->handler, "call-channel", &call, NULL);
3604 /* We won't get notify::call-channel for this channel, so
3605 * directly call the callback. */
3606 call_handler_notify_call_cb (priv->handler, NULL, self);
3607 g_object_unref (call);
3612 empathy_call_window_realized_cb (GtkWidget *widget,
3613 EmpathyCallWindow *self)
3617 /* Make the hangup button twice as wide */
3618 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3619 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3621 empathy_call_window_connect_handler (self);
3623 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3627 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3628 EmpathyCallWindow *window)
3630 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3632 if (priv->pipeline != NULL)
3634 if (priv->bus_message_source_id != 0)
3636 g_source_remove (priv->bus_message_source_id);
3637 priv->bus_message_source_id = 0;
3640 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3643 if (priv->call_state == CONNECTING)
3644 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3650 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3653 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3655 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3660 gtk_widget_hide (priv->dtmf_panel);
3661 gtk_widget_hide (menu);
3662 gtk_widget_hide (priv->toolbar);
3666 if (priv->dialpad_was_visible_before_fs)
3667 gtk_widget_show (priv->dtmf_panel);
3669 gtk_widget_show (menu);
3670 gtk_widget_show (priv->toolbar);
3672 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3673 priv->original_height_before_fs);
3678 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3680 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3682 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3683 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3684 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3685 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3687 if (priv->video_output != NULL)
3690 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3691 priv->video_output, TRUE, TRUE,
3692 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3699 empathy_call_window_state_event_cb (GtkWidget *widget,
3700 GdkEventWindowState *event, EmpathyCallWindow *window)
3702 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3704 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3705 gboolean set_fullscreen = event->new_window_state &
3706 GDK_WINDOW_STATE_FULLSCREEN;
3710 gboolean dialpad_was_visible;
3711 GtkAllocation allocation;
3712 gint original_width, original_height;
3714 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3715 original_width = allocation.width;
3716 original_height = allocation.height;
3718 g_object_get (priv->dtmf_panel,
3719 "visible", &dialpad_was_visible,
3722 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3723 priv->original_width_before_fs = original_width;
3724 priv->original_height_before_fs = original_height;
3726 if (priv->video_output_motion_handler_id == 0 &&
3727 priv->video_output != NULL)
3729 priv->video_output_motion_handler_id = g_signal_connect (
3730 G_OBJECT (priv->video_container), "motion-notify-event",
3731 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3737 disconnect_video_output_motion_handler (window);
3740 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3742 show_controls (window, set_fullscreen);
3743 show_borders (window, set_fullscreen);
3744 gtk_action_set_stock_id (priv->menu_fullscreen,
3745 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3746 priv->is_fullscreen = set_fullscreen;
3753 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3756 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3757 int w, h, dialpad_width;
3758 GtkAllocation allocation;
3760 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3761 w = allocation.width;
3762 h = allocation.height;
3764 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3768 gtk_widget_show (priv->dtmf_panel);
3774 gtk_widget_hide (priv->dtmf_panel);
3778 gtk_window_resize (GTK_WINDOW (window), w, h);
3782 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3785 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3786 TpyCallChannel *call;
3788 priv->sending_video = (state == CAMERA_STATE_ON);
3790 if (state == CAMERA_STATE_ON)
3792 /* When we start sending video, we want to show the video preview by
3794 display_video_preview (window, TRUE);
3798 display_video_preview (window, FALSE);
3801 if (priv->call_state != CONNECTED)
3804 g_object_get (priv->handler, "call-channel", &call, NULL);
3805 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3806 tpy_call_channel_send_video (call, priv->sending_video);
3807 g_object_unref (call);
3811 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3812 EmpathyCallWindow *self)
3814 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3817 active = (gtk_toggle_tool_button_get_active (toggle));
3819 /* We don't want the settings callback to react to this change to avoid
3821 g_signal_handlers_block_by_func (priv->settings,
3822 empathy_call_window_prefs_volume_changed_cb, self);
3826 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3827 priv->volume * 100);
3831 /* TODO, Instead of setting the input volume to 0 we should probably
3832 * stop sending but this would cause the audio call to drop if both
3833 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3834 * in the future. GNOME #574574
3836 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3840 g_signal_handlers_unblock_by_func (priv->settings,
3841 empathy_call_window_prefs_volume_changed_cb, self);
3845 empathy_call_window_hangup_cb (gpointer object,
3846 EmpathyCallWindow *self)
3848 empathy_call_handler_stop_call (self->priv->handler);
3850 empathy_call_window_disconnected (self, TRUE);
3854 empathy_call_window_restart_call (EmpathyCallWindow *window)
3856 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3858 /* Remove error info bars */
3859 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3860 (GtkCallback) gtk_widget_destroy, NULL);
3862 create_video_output_widget (window);
3864 /* While the call was disconnected, the input volume might have changed.
3865 * However, since the audio_input source was destroyed, its volume has not
3866 * been updated during that time. That's why we manually update it here */
3867 empathy_call_window_mic_volume_changed (window);
3869 priv->outgoing = TRUE;
3870 empathy_call_window_set_state_connecting (window);
3872 if (priv->pipeline_playing)
3873 start_call (window);
3875 /* call will be started when the pipeline is ready */
3876 priv->start_call_when_playing = TRUE;
3878 empathy_call_window_setup_avatars (window, priv->handler);
3880 empathy_call_window_show_hangup_button (window, TRUE);
3884 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3885 EmpathyCallWindow *window)
3889 active = gtk_toggle_tool_button_get_active (button);
3891 empathy_call_window_show_dialpad (window, active);
3895 empathy_call_window_fullscreen_cb (gpointer object,
3896 EmpathyCallWindow *window)
3898 empathy_call_window_fullscreen_toggle (window);
3902 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3904 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3906 if (priv->is_fullscreen)
3907 gtk_window_unfullscreen (GTK_WINDOW (window));
3909 gtk_window_fullscreen (GTK_WINDOW (window));
3913 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3914 GdkEventButton *event, EmpathyCallWindow *window)
3916 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3918 empathy_call_window_video_menu_popup (window, event->button);
3926 empathy_call_window_key_press_cb (GtkWidget *video_output,
3927 GdkEventKey *event, EmpathyCallWindow *window)
3929 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3931 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3933 /* Since we are in fullscreen mode, toggling will bring us back to
3935 empathy_call_window_fullscreen_toggle (window);
3943 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3944 GdkEventMotion *event, EmpathyCallWindow *window)
3946 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3948 if (priv->is_fullscreen)
3950 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3952 /* Show the bottom toolbar */
3953 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3960 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3964 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3966 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3968 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3969 button, gtk_get_current_event_time ());
3970 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3974 empathy_call_window_status_message (EmpathyCallWindow *self,
3977 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3981 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3982 gdouble value, EmpathyCallWindow *window)
3984 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3986 if (priv->audio_output == NULL)
3989 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3994 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3996 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3998 return priv->ui_manager;
4001 EmpathyGstAudioSrc *
4002 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4004 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4006 return (EmpathyGstAudioSrc *) priv->audio_input;
4009 EmpathyGstVideoSrc *
4010 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4012 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);