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;
2264 g_assert (priv->handler != NULL);
2266 g_object_get (priv->handler, "call-channel", &call, NULL);
2267 priv->outgoing = (call == NULL);
2269 g_object_unref (call);
2271 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2272 g_assert (priv->contact != NULL);
2274 if (!empathy_contact_can_voip_video (priv->contact))
2276 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2277 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2280 empathy_call_window_setup_avatars (self, priv->handler);
2281 empathy_call_window_set_state_connecting (self);
2283 if (!empathy_call_handler_has_initial_video (priv->handler))
2285 gtk_toggle_tool_button_set_active (
2286 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2288 /* If call has InitialVideo, the preview will be started once the call has
2289 * been started (start_call()). */
2291 update_send_codec (self, TRUE);
2292 update_send_codec (self, FALSE);
2293 update_recv_codec (self, TRUE);
2294 update_recv_codec (self, FALSE);
2296 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2297 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2298 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2299 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2300 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2301 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2302 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2303 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2305 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2306 G_CALLBACK (candidates_changed_cb), self, 0);
2309 static void empathy_call_window_dispose (GObject *object);
2310 static void empathy_call_window_finalize (GObject *object);
2313 empathy_call_window_set_property (GObject *object,
2314 guint property_id, const GValue *value, GParamSpec *pspec)
2316 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2318 switch (property_id)
2320 case PROP_CALL_HANDLER:
2321 priv->handler = g_value_dup_object (value);
2324 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2329 empathy_call_window_get_property (GObject *object,
2330 guint property_id, GValue *value, GParamSpec *pspec)
2332 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2334 switch (property_id)
2336 case PROP_CALL_HANDLER:
2337 g_value_set_object (value, priv->handler);
2340 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2345 empathy_call_window_class_init (
2346 EmpathyCallWindowClass *empathy_call_window_class)
2348 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2349 GParamSpec *param_spec;
2351 g_type_class_add_private (empathy_call_window_class,
2352 sizeof (EmpathyCallWindowPriv));
2354 object_class->constructed = empathy_call_window_constructed;
2355 object_class->set_property = empathy_call_window_set_property;
2356 object_class->get_property = empathy_call_window_get_property;
2358 object_class->dispose = empathy_call_window_dispose;
2359 object_class->finalize = empathy_call_window_finalize;
2361 param_spec = g_param_spec_object ("handler",
2362 "handler", "The call handler",
2363 EMPATHY_TYPE_CALL_HANDLER,
2364 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2365 g_object_class_install_property (object_class,
2366 PROP_CALL_HANDLER, param_spec);
2370 empathy_call_window_dispose (GObject *object)
2372 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2373 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2375 if (priv->dispose_has_run)
2378 priv->dispose_has_run = TRUE;
2380 if (priv->handler != NULL)
2382 empathy_call_handler_stop_call (priv->handler);
2383 tp_clear_object (&priv->handler);
2386 if (priv->bus_message_source_id != 0)
2388 g_source_remove (priv->bus_message_source_id);
2389 priv->bus_message_source_id = 0;
2392 if (priv->got_video_src > 0)
2394 g_source_remove (priv->got_video_src);
2395 priv->got_video_src = 0;
2398 if (priv->inactivity_src > 0)
2400 g_source_remove (priv->inactivity_src);
2401 priv->inactivity_src = 0;
2404 tp_clear_object (&priv->pipeline);
2405 tp_clear_object (&priv->video_input);
2406 tp_clear_object (&priv->audio_input);
2407 tp_clear_object (&priv->video_tee);
2408 tp_clear_object (&priv->ui_manager);
2409 tp_clear_object (&priv->fullscreen);
2410 tp_clear_object (&priv->camera_monitor);
2411 tp_clear_object (&priv->settings);
2412 tp_clear_object (&priv->sound_mgr);
2413 tp_clear_object (&priv->mic_menu);
2414 tp_clear_object (&priv->camera_menu);
2416 g_list_free_full (priv->notifiers, g_object_unref);
2418 if (priv->timer_id != 0)
2419 g_source_remove (priv->timer_id);
2422 if (priv->contact != NULL)
2424 g_signal_handlers_disconnect_by_func (priv->contact,
2425 contact_name_changed_cb, self);
2426 priv->contact = NULL;
2429 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2433 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2435 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2437 if (priv->video_output_motion_handler_id != 0)
2439 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2440 priv->video_output_motion_handler_id);
2441 priv->video_output_motion_handler_id = 0;
2446 empathy_call_window_finalize (GObject *object)
2448 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2449 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2451 disconnect_video_output_motion_handler (self);
2453 /* free any data held directly by the object here */
2454 g_mutex_free (priv->lock);
2456 g_timer_destroy (priv->timer);
2458 g_string_free (priv->tones, TRUE);
2460 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2465 empathy_call_window_new (EmpathyCallHandler *handler)
2467 return EMPATHY_CALL_WINDOW (
2468 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2472 empathy_call_window_present (EmpathyCallWindow *self,
2473 EmpathyCallHandler *handler)
2475 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2477 tp_clear_object (&self->priv->handler);
2478 self->priv->handler = g_object_ref (handler);
2479 empathy_call_window_connect_handler (self);
2481 empathy_window_present (GTK_WINDOW (self));
2482 empathy_call_window_restart_call (self);
2486 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2487 GstElement *conference, gpointer user_data)
2489 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2490 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2491 FsElementAddedNotifier *notifier;
2494 DEBUG ("Conference added");
2496 /* Add notifier to set the various element properties as needed */
2497 notifier = fs_element_added_notifier_new ();
2498 keyfile = fs_utils_get_default_element_properties (conference);
2500 if (keyfile != NULL)
2501 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2503 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2505 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2507 gst_bin_add (GST_BIN (priv->pipeline), conference);
2508 gst_element_set_state (conference, GST_STATE_PLAYING);
2512 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2513 GstElement *conference, gpointer user_data)
2515 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2516 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2518 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2519 gst_element_set_state (conference, GST_STATE_NULL);
2523 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2525 GstStateChangeReturn state_change_return;
2526 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2528 if (priv->pipeline == NULL)
2531 if (priv->bus_message_source_id != 0)
2533 g_source_remove (priv->bus_message_source_id);
2534 priv->bus_message_source_id = 0;
2537 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2539 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2540 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2542 if (priv->pipeline != NULL)
2543 g_object_unref (priv->pipeline);
2544 priv->pipeline = NULL;
2546 if (priv->audio_output != NULL)
2547 g_object_unref (priv->audio_output);
2548 priv->audio_output = NULL;
2550 if (priv->video_tee != NULL)
2551 g_object_unref (priv->video_tee);
2552 priv->video_tee = NULL;
2554 if (priv->video_preview != NULL)
2555 clutter_actor_destroy (priv->video_preview);
2556 priv->video_preview = NULL;
2558 /* If we destroy the preview while it's being dragged, we won't
2559 * get the ::drag-end signal, so manually destroy the clone */
2560 if (priv->drag_preview != NULL)
2562 clutter_actor_destroy (priv->drag_preview);
2563 empathy_call_window_show_preview_rectangles (self, FALSE);
2564 priv->drag_preview = NULL;
2567 priv->funnel = NULL;
2569 create_pipeline (self);
2570 /* Call will be started when user will hit the 'redial' button */
2571 priv->start_call_when_playing = FALSE;
2572 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2578 g_message ("Error: could not destroy pipeline. Closing call window");
2579 gtk_widget_destroy (GTK_WIDGET (self));
2586 reset_details_pane (EmpathyCallWindow *self)
2588 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2590 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2591 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2592 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2593 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2597 empathy_call_window_disconnected (EmpathyCallWindow *self,
2600 gboolean could_disconnect = FALSE;
2601 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2602 gboolean could_reset_pipeline;
2604 /* Leave full screen mode if needed */
2605 gtk_window_unfullscreen (GTK_WINDOW (self));
2607 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2608 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2610 priv->sending_tones = FALSE;
2611 g_string_set_size (priv->tones, 0);
2613 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2615 if (priv->call_state == CONNECTING)
2616 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2618 if (priv->call_state != REDIALING)
2619 priv->call_state = DISCONNECTED;
2621 /* Show the toolbar */
2622 clutter_state_set_state (priv->transitions, "fade-in");
2624 if (could_reset_pipeline)
2626 g_mutex_lock (priv->lock);
2628 g_timer_stop (priv->timer);
2630 if (priv->timer_id != 0)
2631 g_source_remove (priv->timer_id);
2634 g_mutex_unlock (priv->lock);
2637 /* We are about to destroy the window, no need to update it or create
2638 * a video preview */
2641 empathy_call_window_status_message (self, _("Disconnected"));
2643 empathy_call_window_show_hangup_button (self, FALSE);
2645 /* Unsensitive the camera and mic button */
2646 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2647 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2649 /* Be sure that the mic button is enabled */
2650 gtk_toggle_tool_button_set_active (
2651 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2653 if (priv->camera_state == CAMERA_STATE_ON)
2655 /* Restart the preview with the new pipeline. */
2656 display_video_preview (self, TRUE);
2659 /* destroy the video output; it will be recreated when we'll redial */
2660 disconnect_video_output_motion_handler (self);
2661 if (priv->video_output != NULL)
2662 clutter_actor_destroy (priv->video_output);
2663 priv->video_output = NULL;
2664 if (priv->got_video_src > 0)
2666 g_source_remove (priv->got_video_src);
2667 priv->got_video_src = 0;
2670 gtk_widget_show (priv->remote_user_avatar_widget);
2672 reset_details_pane (self);
2674 priv->sending_video = FALSE;
2675 priv->call_started = FALSE;
2677 could_disconnect = TRUE;
2679 /* TODO: display the self avatar of the preview (depends if the "Always
2680 * Show Video Preview" is enabled or not) */
2683 return could_disconnect;
2688 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2691 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2692 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2694 if (empathy_call_window_disconnected (self, TRUE) &&
2695 priv->call_state == REDIALING)
2696 empathy_call_window_restart_call (self);
2700 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2702 FsMediaType media_type,
2703 EmpathyCallWindow *self)
2705 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2707 DEBUG ("removing content");
2710 * This assumes that there is only one video stream per channel...
2713 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2715 if (priv->funnel != NULL)
2719 output = priv->video_output_sink;
2721 gst_element_set_state (output, GST_STATE_NULL);
2722 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2724 gst_bin_remove (GST_BIN (priv->pipeline), output);
2725 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2726 priv->funnel = NULL;
2730 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2732 if (priv->audio_output != NULL)
2734 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2736 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2737 priv->audio_output = NULL;
2745 /* Called with global lock held */
2747 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2749 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2753 if (priv->funnel == NULL)
2755 output = priv->video_output_sink;
2757 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2761 g_warning ("Could not create fsfunnel");
2765 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2767 gst_object_unref (priv->funnel);
2768 priv->funnel = NULL;
2769 g_warning ("Could not add funnel to pipeline");
2773 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2775 g_warning ("Could not add the video output widget to the pipeline");
2779 if (!gst_element_link (priv->funnel, output))
2781 g_warning ("Could not link output sink to funnel");
2782 goto error_output_added;
2785 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2787 g_warning ("Could not start video sink");
2788 goto error_output_added;
2791 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2793 g_warning ("Could not start funnel");
2794 goto error_output_added;
2798 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2801 g_warning ("Could not get request pad from funnel");
2808 gst_element_set_locked_state (priv->funnel, TRUE);
2809 gst_element_set_locked_state (output, TRUE);
2811 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2812 gst_element_set_state (output, GST_STATE_NULL);
2814 gst_bin_remove (GST_BIN (priv->pipeline), output);
2815 gst_element_set_locked_state (output, FALSE);
2819 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2820 priv->funnel = NULL;
2825 /* Called with global lock held */
2827 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2829 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2831 GstPadTemplate *template;
2833 if (priv->audio_output == NULL)
2835 priv->audio_output = empathy_audio_sink_new ();
2836 g_object_ref_sink (priv->audio_output);
2838 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2840 g_warning ("Could not add audio sink to pipeline");
2841 g_object_unref (priv->audio_output);
2842 goto error_add_output;
2845 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2847 g_warning ("Could not start audio sink");
2852 template = gst_element_class_get_pad_template (
2853 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2855 pad = gst_element_request_pad (priv->audio_output,
2856 template, NULL, NULL);
2860 g_warning ("Could not get sink pad from sink");
2867 gst_element_set_locked_state (priv->audio_output, TRUE);
2868 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2869 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2870 priv->audio_output = NULL;
2878 empathy_call_window_update_timer (gpointer user_data)
2880 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2881 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2882 const gchar *status;
2886 time_ = g_timer_elapsed (priv->timer, NULL);
2888 if (priv->call_state == HELD)
2889 status = _("On hold");
2890 else if (!gtk_toggle_tool_button_get_active (
2891 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2894 status = _("Duration");
2896 /* Translators: 'status - minutes:seconds' the caller has been connected */
2897 str = g_strdup_printf (_("%s — %d:%02dm"),
2899 (int) time_ / 60, (int) time_ % 60);
2900 empathy_call_window_status_message (self, str);
2908 display_error (EmpathyCallWindow *self,
2909 TpyCallChannel *call,
2913 const gchar *details)
2915 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2916 GtkWidget *info_bar;
2917 GtkWidget *content_area;
2924 /* Create info bar */
2925 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2928 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2930 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2932 /* hbox containing the image and the messages vbox */
2933 hbox = gtk_hbox_new (FALSE, 3);
2934 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2937 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2938 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2940 /* vbox containing the main message and the details expander */
2941 vbox = gtk_vbox_new (FALSE, 3);
2942 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2945 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2947 label = gtk_label_new (NULL);
2948 gtk_label_set_markup (GTK_LABEL (label), txt);
2949 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2950 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2953 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2956 if (details != NULL)
2958 GtkWidget *expander;
2960 expander = gtk_expander_new (_("Technical Details"));
2962 txt = g_strdup_printf ("<i>%s</i>", details);
2964 label = gtk_label_new (NULL);
2965 gtk_label_set_markup (GTK_LABEL (label), txt);
2966 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2967 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2970 gtk_container_add (GTK_CONTAINER (expander), label);
2971 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2974 g_signal_connect (info_bar, "response",
2975 G_CALLBACK (gtk_widget_destroy), NULL);
2977 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2978 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2979 gtk_widget_show_all (info_bar);
2983 media_stream_error_to_txt (EmpathyCallWindow *self,
2984 TpyCallChannel *call,
2986 TpMediaStreamError error)
2988 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2989 const gchar *cm = NULL;
2995 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2997 return g_strdup_printf (
2998 _("%s's software does not understand any of the audio formats "
2999 "supported by your computer"),
3000 empathy_contact_get_alias (priv->contact));
3002 return g_strdup_printf (
3003 _("%s's software does not understand any of the video formats "
3004 "supported by your computer"),
3005 empathy_contact_get_alias (priv->contact));
3007 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3008 return g_strdup_printf (
3009 _("Can't establish a connection to %s. "
3010 "One of you might be on a network that does not allow "
3011 "direct connections."),
3012 empathy_contact_get_alias (priv->contact));
3014 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3015 return g_strdup (_("There was a failure on the network"));
3017 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3019 return g_strdup (_("The audio formats necessary for this call "
3020 "are not installed on your computer"));
3022 return g_strdup (_("The video formats necessary for this call "
3023 "are not installed on your computer"));
3025 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3026 tp_connection_parse_object_path (
3027 tp_channel_borrow_connection (TP_CHANNEL (call)),
3030 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3031 "product=Telepathy&component=%s", cm);
3033 result = g_strdup_printf (
3034 _("Something unexpected happened in a Telepathy component. "
3035 "Please <a href=\"%s\">report this bug</a> and attach "
3036 "logs gathered from the 'Debug' window in the Help menu."), url);
3042 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3043 return g_strdup (_("There was a failure in the call engine"));
3045 case TP_MEDIA_STREAM_ERROR_EOS:
3046 return g_strdup (_("The end of the stream was reached"));
3048 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3055 empathy_call_window_stream_error (EmpathyCallWindow *self,
3056 TpyCallChannel *call,
3065 desc = media_stream_error_to_txt (self, call, audio, code);
3068 /* No description, use the error message. That's not great as it's not
3069 * localized but it's better than nothing. */
3070 display_error (self, call, icon, title, msg, NULL);
3074 display_error (self, call, icon, title, desc, msg);
3080 empathy_call_window_audio_stream_error (TpyCallChannel *call,
3083 EmpathyCallWindow *self)
3085 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3086 "gnome-stock-mic", _("Can't establish audio stream"));
3090 empathy_call_window_video_stream_error (TpyCallChannel *call,
3093 EmpathyCallWindow *self)
3095 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3096 "camera-web", _("Can't establish video stream"));
3101 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3103 EmpathyCallWindow *self)
3105 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3106 TpyCallChannel *call;
3107 gboolean can_send_video;
3109 if (state != TPY_CALL_STATE_ACCEPTED)
3112 if (priv->call_state == CONNECTED)
3115 g_timer_start (priv->timer);
3116 priv->call_state = CONNECTED;
3118 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3120 can_send_video = priv->video_input != NULL &&
3121 empathy_contact_can_voip_video (priv->contact) &&
3122 empathy_camera_monitor_get_available (priv->camera_monitor);
3124 g_object_get (priv->handler, "call-channel", &call, NULL);
3126 if (tpy_call_channel_has_dtmf (call))
3127 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3129 if (priv->video_input == NULL)
3130 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3132 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3134 empathy_call_window_show_hangup_button (self, TRUE);
3136 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3138 clutter_actor_hide (priv->video_output);
3139 gtk_widget_show (priv->remote_user_avatar_widget);
3141 g_object_unref (call);
3143 g_mutex_lock (priv->lock);
3145 priv->timer_id = g_timeout_add_seconds (1,
3146 empathy_call_window_update_timer, self);
3148 g_mutex_unlock (priv->lock);
3150 empathy_call_window_update_timer (self);
3152 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3156 empathy_call_window_show_video_output_cb (gpointer user_data)
3158 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3160 if (self->priv->video_output != NULL)
3162 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3163 clutter_actor_show (self->priv->video_output);
3164 empathy_call_window_raise_actors (self);
3171 empathy_call_window_check_video_cb (gpointer data)
3173 EmpathyCallWindow *self = data;
3175 if (self->priv->got_video)
3177 self->priv->got_video = FALSE;
3181 /* No video in the last N seconds, display the remote avatar */
3182 empathy_call_window_show_video_output (self, FALSE);
3187 /* Called from the streaming thread */
3189 empathy_call_window_video_probe_cb (GstPad *pad,
3190 GstMiniObject *mini_obj,
3191 EmpathyCallWindow *self)
3194 if (GST_IS_EVENT (mini_obj))
3197 if (G_UNLIKELY (!self->priv->got_video))
3199 /* show the remote video */
3200 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3201 empathy_call_window_show_video_output_cb,
3202 g_object_ref (self), g_object_unref);
3204 self->priv->got_video = TRUE;
3210 /* Called from the streaming thread */
3212 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3213 GstPad *src, guint media_type, gpointer user_data)
3215 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3216 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3217 gboolean retval = FALSE;
3221 g_mutex_lock (priv->lock);
3225 case TP_MEDIA_STREAM_TYPE_AUDIO:
3226 pad = empathy_call_window_get_audio_sink_pad (self);
3228 case TP_MEDIA_STREAM_TYPE_VIDEO:
3229 g_idle_add (empathy_call_window_show_video_output_cb, self);
3230 pad = empathy_call_window_get_video_sink_pad (self);
3232 gst_pad_add_data_probe (src,
3233 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3234 if (priv->got_video_src > 0)
3235 g_source_remove (priv->got_video_src);
3236 priv->got_video_src = g_timeout_add_seconds (5,
3237 empathy_call_window_check_video_cb, self);
3240 g_assert_not_reached ();
3246 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3247 g_warning ("Could not link %s sink pad",
3248 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3252 gst_object_unref (pad);
3256 /* If no sink could be linked, try to add fakesink to prevent the whole call
3261 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3263 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3265 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3266 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3267 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3269 gst_element_set_locked_state (fakesink, TRUE);
3270 gst_element_set_state (fakesink, GST_STATE_NULL);
3271 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3275 DEBUG ("Could not link real sink, linked fakesink instead");
3277 gst_object_unref (sinkpad);
3281 gst_object_unref (fakesink);
3286 g_mutex_unlock (priv->lock);
3292 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
3293 GstPad *sink, FsMediaType media_type, gpointer user_data)
3295 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3296 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3298 gboolean retval = FALSE;
3302 case FS_MEDIA_TYPE_AUDIO:
3303 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3305 g_warning ("Could not add audio source to pipeline");
3309 pad = gst_element_get_static_pad (priv->audio_input, "src");
3312 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3313 g_warning ("Could not get source pad from audio source");
3317 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3319 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3320 g_warning ("Could not link audio source to farsight");
3324 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3326 g_warning ("Could not start audio source");
3327 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3328 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3334 case FS_MEDIA_TYPE_VIDEO:
3335 if (priv->video_tee != NULL)
3337 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3338 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3340 g_warning ("Could not link video source input pipeline");
3343 gst_object_unref (pad);
3349 g_assert_not_reached ();
3356 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3358 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3359 GstElement *preview;
3361 disable_camera (self);
3363 DEBUG ("remove video input");
3364 preview = priv->video_preview_sink;
3366 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3367 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3368 gst_element_set_state (preview, GST_STATE_NULL);
3370 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3373 g_object_unref (priv->video_input);
3374 priv->video_input = NULL;
3375 g_object_unref (priv->video_tee);
3376 priv->video_tee = NULL;
3377 clutter_actor_destroy (priv->video_preview);
3378 priv->video_preview = NULL;
3380 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3384 start_call (EmpathyCallWindow *self)
3386 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3388 priv->call_started = TRUE;
3389 empathy_call_handler_start_call (priv->handler,
3390 gtk_get_current_event_time ());
3392 if (empathy_call_handler_has_initial_video (priv->handler))
3394 TpyCallChannel *call;
3397 g_object_get (priv->handler, "call-channel", &call, NULL);
3398 s = tpy_call_channel_get_video_state (call);
3400 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3401 s == TPY_SENDING_STATE_SENDING)
3403 /* Enable 'send video' buttons and display the preview */
3404 gtk_toggle_tool_button_set_active (
3405 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3409 gtk_toggle_tool_button_set_active (
3410 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3412 if (priv->video_preview == NULL)
3414 create_video_preview (self);
3415 add_video_preview_to_pipeline (self);
3419 g_object_unref (call);
3424 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3427 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3428 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3429 GstState newstate, pending;
3431 empathy_call_handler_bus_message (priv->handler, bus, message);
3433 switch (GST_MESSAGE_TYPE (message))
3435 case GST_MESSAGE_STATE_CHANGED:
3436 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3438 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3440 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3441 !priv->call_started)
3443 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3444 if (newstate == GST_STATE_PAUSED)
3446 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3447 priv->pipeline_playing = TRUE;
3449 if (priv->start_call_when_playing)
3453 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3455 gst_message_parse_state_changed (message, NULL, &newstate,
3458 if (newstate == GST_STATE_PLAYING &&
3459 pending == GST_STATE_VOID_PENDING)
3460 empathy_call_window_stop_camera_spinning (self);
3463 case GST_MESSAGE_ERROR:
3465 GError *error = NULL;
3466 GstElement *gst_error;
3469 gst_message_parse_error (message, &error, &debug);
3470 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3472 g_message ("Element error: %s -- %s\n", error->message, debug);
3474 if (g_str_has_prefix (gst_element_get_name (gst_error),
3475 VIDEO_INPUT_ERROR_PREFIX))
3477 /* Remove the video input and continue */
3478 if (priv->video_input != NULL)
3479 empathy_call_window_remove_video_input (self);
3480 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3484 empathy_call_window_disconnected (self, TRUE);
3486 g_error_free (error);
3489 case GST_MESSAGE_UNKNOWN:
3490 case GST_MESSAGE_EOS:
3491 case GST_MESSAGE_WARNING:
3492 case GST_MESSAGE_INFO:
3493 case GST_MESSAGE_TAG:
3494 case GST_MESSAGE_BUFFERING:
3495 case GST_MESSAGE_STATE_DIRTY:
3496 case GST_MESSAGE_STEP_DONE:
3497 case GST_MESSAGE_CLOCK_PROVIDE:
3498 case GST_MESSAGE_CLOCK_LOST:
3499 case GST_MESSAGE_NEW_CLOCK:
3500 case GST_MESSAGE_STRUCTURE_CHANGE:
3501 case GST_MESSAGE_STREAM_STATUS:
3502 case GST_MESSAGE_APPLICATION:
3503 case GST_MESSAGE_ELEMENT:
3504 case GST_MESSAGE_SEGMENT_START:
3505 case GST_MESSAGE_SEGMENT_DONE:
3506 case GST_MESSAGE_DURATION:
3507 case GST_MESSAGE_ANY:
3516 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3517 GHashTable *members,
3518 EmpathyCallWindow *self)
3520 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3521 GHashTableIter iter;
3522 gpointer key, value;
3523 gboolean held = FALSE;
3525 g_hash_table_iter_init (&iter, members);
3526 while (g_hash_table_iter_next (&iter, &key, &value))
3528 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3530 /* This assumes this is a 1-1 call, otherwise one participant
3531 * putting the call on hold wouldn't mean the call is on hold
3539 priv->call_state = HELD;
3540 else if (priv->call_state == HELD)
3541 priv->call_state = CONNECTED;
3545 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3547 EmpathyCallWindow *self)
3549 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3550 TpyCallChannel *call;
3552 g_object_get (priv->handler, "call-channel", &call, NULL);
3557 tp_g_signal_connect_object (call, "audio-stream-error",
3558 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3559 tp_g_signal_connect_object (call, "video-stream-error",
3560 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3563 tp_g_signal_connect_object (call, "members-changed",
3564 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3566 tp_cli_channel_interface_dtmf_connect_to_stopped_tones (TP_CHANNEL (call),
3567 empathy_call_window_tones_stopped_cb, self, NULL,
3568 G_OBJECT (call), NULL);
3570 g_object_unref (call);
3574 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3576 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3577 TpyCallChannel *call;
3579 g_signal_connect (priv->handler, "state-changed",
3580 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3581 g_signal_connect (priv->handler, "conference-added",
3582 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3583 g_signal_connect (priv->handler, "conference-removed",
3584 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3585 g_signal_connect (priv->handler, "closed",
3586 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3587 g_signal_connect (priv->handler, "src-pad-added",
3588 G_CALLBACK (empathy_call_window_src_added_cb), self);
3589 g_signal_connect (priv->handler, "sink-pad-added",
3590 G_CALLBACK (empathy_call_window_sink_added_cb), self);
3591 g_signal_connect (priv->handler, "sink-pad-removed",
3592 G_CALLBACK (empathy_call_window_sink_removed_cb), self);
3594 /* We connect to ::call-channel unconditionally since we'll
3595 * get new channels if we hangup and redial or if we reuse the
3597 g_signal_connect (priv->handler, "notify::call-channel",
3598 G_CALLBACK (call_handler_notify_call_cb), self);
3600 g_object_get (priv->handler, "call-channel", &call, NULL);
3603 /* We won't get notify::call-channel for this channel, so
3604 * directly call the callback. */
3605 call_handler_notify_call_cb (priv->handler, NULL, self);
3606 g_object_unref (call);
3611 empathy_call_window_realized_cb (GtkWidget *widget,
3612 EmpathyCallWindow *self)
3616 /* Make the hangup button twice as wide */
3617 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3618 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3620 empathy_call_window_connect_handler (self);
3622 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3626 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3627 EmpathyCallWindow *window)
3629 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3631 if (priv->pipeline != NULL)
3633 if (priv->bus_message_source_id != 0)
3635 g_source_remove (priv->bus_message_source_id);
3636 priv->bus_message_source_id = 0;
3639 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3642 if (priv->call_state == CONNECTING)
3643 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3649 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3652 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3654 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3659 gtk_widget_hide (priv->dtmf_panel);
3660 gtk_widget_hide (menu);
3661 gtk_widget_hide (priv->toolbar);
3665 if (priv->dialpad_was_visible_before_fs)
3666 gtk_widget_show (priv->dtmf_panel);
3668 gtk_widget_show (menu);
3669 gtk_widget_show (priv->toolbar);
3671 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3672 priv->original_height_before_fs);
3677 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3679 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3681 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3682 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3683 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3684 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3686 if (priv->video_output != NULL)
3689 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3690 priv->video_output, TRUE, TRUE,
3691 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3698 empathy_call_window_state_event_cb (GtkWidget *widget,
3699 GdkEventWindowState *event, EmpathyCallWindow *window)
3701 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3703 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3704 gboolean set_fullscreen = event->new_window_state &
3705 GDK_WINDOW_STATE_FULLSCREEN;
3709 gboolean dialpad_was_visible;
3710 GtkAllocation allocation;
3711 gint original_width, original_height;
3713 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3714 original_width = allocation.width;
3715 original_height = allocation.height;
3717 g_object_get (priv->dtmf_panel,
3718 "visible", &dialpad_was_visible,
3721 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3722 priv->original_width_before_fs = original_width;
3723 priv->original_height_before_fs = original_height;
3725 if (priv->video_output_motion_handler_id == 0 &&
3726 priv->video_output != NULL)
3728 priv->video_output_motion_handler_id = g_signal_connect (
3729 G_OBJECT (priv->video_container), "motion-notify-event",
3730 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3736 disconnect_video_output_motion_handler (window);
3739 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3741 show_controls (window, set_fullscreen);
3742 show_borders (window, set_fullscreen);
3743 gtk_action_set_stock_id (priv->menu_fullscreen,
3744 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3745 priv->is_fullscreen = set_fullscreen;
3752 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3755 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3756 int w, h, dialpad_width;
3757 GtkAllocation allocation;
3759 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3760 w = allocation.width;
3761 h = allocation.height;
3763 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3767 gtk_widget_show (priv->dtmf_panel);
3773 gtk_widget_hide (priv->dtmf_panel);
3777 gtk_window_resize (GTK_WINDOW (window), w, h);
3781 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3784 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3785 TpyCallChannel *call;
3787 priv->sending_video = (state == CAMERA_STATE_ON);
3789 if (state == CAMERA_STATE_ON)
3791 /* When we start sending video, we want to show the video preview by
3793 display_video_preview (window, TRUE);
3797 display_video_preview (window, FALSE);
3800 if (priv->call_state != CONNECTED)
3803 g_object_get (priv->handler, "call-channel", &call, NULL);
3804 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3805 tpy_call_channel_send_video (call, priv->sending_video);
3806 g_object_unref (call);
3810 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3811 EmpathyCallWindow *self)
3813 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3816 active = (gtk_toggle_tool_button_get_active (toggle));
3818 /* We don't want the settings callback to react to this change to avoid
3820 g_signal_handlers_block_by_func (priv->settings,
3821 empathy_call_window_prefs_volume_changed_cb, self);
3825 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3826 priv->volume * 100);
3830 /* TODO, Instead of setting the input volume to 0 we should probably
3831 * stop sending but this would cause the audio call to drop if both
3832 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3833 * in the future. GNOME #574574
3835 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3839 g_signal_handlers_unblock_by_func (priv->settings,
3840 empathy_call_window_prefs_volume_changed_cb, self);
3844 empathy_call_window_hangup_cb (gpointer object,
3845 EmpathyCallWindow *self)
3847 empathy_call_handler_stop_call (self->priv->handler);
3849 empathy_call_window_disconnected (self, TRUE);
3853 empathy_call_window_restart_call (EmpathyCallWindow *window)
3855 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3857 /* Remove error info bars */
3858 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3859 (GtkCallback) gtk_widget_destroy, NULL);
3861 create_video_output_widget (window);
3863 /* While the call was disconnected, the input volume might have changed.
3864 * However, since the audio_input source was destroyed, its volume has not
3865 * been updated during that time. That's why we manually update it here */
3866 empathy_call_window_mic_volume_changed (window);
3868 priv->outgoing = TRUE;
3869 empathy_call_window_set_state_connecting (window);
3871 if (priv->pipeline_playing)
3872 start_call (window);
3874 /* call will be started when the pipeline is ready */
3875 priv->start_call_when_playing = TRUE;
3877 empathy_call_window_setup_avatars (window, priv->handler);
3879 empathy_call_window_show_hangup_button (window, TRUE);
3883 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3884 EmpathyCallWindow *window)
3888 active = gtk_toggle_tool_button_get_active (button);
3890 empathy_call_window_show_dialpad (window, active);
3894 empathy_call_window_fullscreen_cb (gpointer object,
3895 EmpathyCallWindow *window)
3897 empathy_call_window_fullscreen_toggle (window);
3901 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3903 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3905 if (priv->is_fullscreen)
3906 gtk_window_unfullscreen (GTK_WINDOW (window));
3908 gtk_window_fullscreen (GTK_WINDOW (window));
3912 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3913 GdkEventButton *event, EmpathyCallWindow *window)
3915 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3917 empathy_call_window_video_menu_popup (window, event->button);
3925 empathy_call_window_key_press_cb (GtkWidget *video_output,
3926 GdkEventKey *event, EmpathyCallWindow *window)
3928 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3930 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3932 /* Since we are in fullscreen mode, toggling will bring us back to
3934 empathy_call_window_fullscreen_toggle (window);
3942 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3943 GdkEventMotion *event, EmpathyCallWindow *window)
3945 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3947 if (priv->is_fullscreen)
3949 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3951 /* Show the bottom toolbar */
3952 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3959 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3963 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3965 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3967 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3968 button, gtk_get_current_event_time ());
3969 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3973 empathy_call_window_status_message (EmpathyCallWindow *self,
3976 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3980 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3981 gdouble value, EmpathyCallWindow *window)
3983 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3985 if (priv->audio_output == NULL)
3988 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3993 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3995 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3997 return priv->ui_manager;
4000 EmpathyGstAudioSrc *
4001 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4003 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4005 return (EmpathyGstAudioSrc *) priv->audio_input;
4008 EmpathyGstVideoSrc *
4009 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4011 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);