2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <gdk/gdkkeysyms.h>
31 #include <glib/gi18n.h>
33 #include <clutter/clutter.h>
34 #include <clutter-gtk/clutter-gtk.h>
35 #include <clutter-gst/clutter-gst.h>
37 #include <telepathy-glib/util.h>
38 #include <telepathy-farstream/telepathy-farstream.h>
39 #include <telepathy-glib/util.h>
41 #include <farstream/fs-element-added-notifier.h>
42 #include <farstream/fs-utils.h>
44 #include <libempathy/empathy-camera-monitor.h>
45 #include <libempathy/empathy-gsettings.h>
46 #include <libempathy/empathy-tp-contact-factory.h>
47 #include <libempathy/empathy-request-util.h>
48 #include <libempathy/empathy-utils.h>
50 #include <libempathy-gtk/empathy-avatar-image.h>
51 #include <libempathy-gtk/empathy-dialpad-widget.h>
52 #include <libempathy-gtk/empathy-ui-utils.h>
53 #include <libempathy-gtk/empathy-sound-manager.h>
54 #include <libempathy-gtk/empathy-geometry.h>
55 #include <libempathy-gtk/empathy-images.h>
56 #include <libempathy-gtk/empathy-call-utils.h>
58 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
59 #include <libempathy/empathy-debug.h>
61 #include "empathy-call-window.h"
62 #include "empathy-call-window-fullscreen.h"
63 #include "empathy-call-factory.h"
64 #include "empathy-video-widget.h"
65 #include "empathy-about-dialog.h"
66 #include "empathy-audio-src.h"
67 #include "empathy-audio-sink.h"
68 #include "empathy-video-src.h"
69 #include "empathy-mic-menu.h"
70 #include "empathy-preferences.h"
71 #include "empathy-rounded-actor.h"
72 #include "empathy-rounded-rectangle.h"
73 #include "empathy-rounded-texture.h"
74 #include "empathy-camera-menu.h"
76 #define CONTENT_HBOX_BORDER_WIDTH 6
77 #define CONTENT_HBOX_SPACING 3
78 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
80 #define SELF_VIDEO_SECTION_WIDTH 120
81 #define SELF_VIDEO_SECTION_HEIGHT 90
82 #define SELF_VIDEO_SECTION_MARGIN 2
83 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
85 #define FLOATING_TOOLBAR_OPACITY 192
86 #define FLOATING_TOOLBAR_SPACING 20
88 /* The avatar's default width and height are set to the same value because we
89 want a square icon. */
90 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
91 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
92 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
94 #define SMALL_TOOLBAR_SIZE 36
96 /* If an video input error occurs, the error message will start with "v4l" */
97 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
99 /* The time interval in milliseconds between 2 outgoing rings */
100 #define MS_BETWEEN_RING 500
102 /* The roundedness of preview box and placeholders */
103 #define PREVIEW_ROUND_FACTOR 16
105 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
108 PROP_CALL_HANDLER = 1,
112 RINGING, /* Incoming call */
113 CONNECTING, /* Outgoing call */
114 CONNECTED, /* Connected */
115 HELD, /* Connected, but on hold */
116 DISCONNECTED, /* Disconnected */
117 REDIALING /* Redialing (special case of CONNECTING) */
121 CAMERA_STATE_OFF = 0,
127 PREVIEW_POS_TOP_LEFT,
128 PREVIEW_POS_TOP_RIGHT,
129 PREVIEW_POS_BOTTOM_LEFT,
130 PREVIEW_POS_BOTTOM_RIGHT,
133 struct _EmpathyCallWindowPriv
135 gboolean dispose_has_run;
136 EmpathyCallHandler *handler;
138 EmpathyContact *contact;
140 EmpathyCameraMonitor *camera_monitor;
145 GtkUIManager *ui_manager;
146 GtkWidget *errors_vbox;
147 /* widget displays the video received from the remote user. This widget is
148 * alive only during call. */
149 ClutterActor *video_output;
150 ClutterActor *video_preview;
151 ClutterActor *drag_preview;
152 ClutterActor *preview_shown_button;
153 ClutterActor *preview_hidden_button;
154 ClutterActor *preview_rectangle1;
155 ClutterActor *preview_rectangle2;
156 ClutterActor *preview_rectangle3;
157 ClutterActor *preview_rectangle4;
158 ClutterActor *preview_spinner_actor;
159 GtkWidget *preview_spinner_widget;
160 GtkWidget *video_container;
161 GtkWidget *remote_user_avatar_widget;
162 GtkWidget *remote_user_avatar_toolbar;
163 GtkWidget *remote_user_name_toolbar;
164 GtkWidget *status_label;
165 GtkWidget *hangup_button;
166 GtkWidget *audio_call_button;
167 GtkWidget *video_call_button;
168 GtkWidget *mic_button;
169 GtkWidget *volume_button;
170 GtkWidget *camera_button;
171 GtkWidget *dialpad_button;
173 GtkWidget *bottom_toolbar;
174 ClutterActor *floating_toolbar;
176 GtkAction *menu_fullscreen;
177 GtkAction *menu_swap_camera;
179 ClutterState *transitions;
181 /* The main box covering all the stage, contaning remote avatar/video */
182 ClutterActor *video_box;
183 ClutterLayoutManager *video_layout;
185 /* A Box layout manager containing a bin for previews
186 * and the floating toolbar */
187 ClutterActor *overlay_box;
188 ClutterLayoutManager *overlay_layout;
190 /* Bin layout for the previews */
191 ClutterActor *preview_box;
192 ClutterLayoutManager *preview_layout;
194 /* Coordinates of the preview drag event's start. */
195 PreviewPosition preview_pos;
197 /* We keep a reference on the hbox which contains the main content so we can
198 easilly repack everything when toggling fullscreen */
199 GtkWidget *content_hbox;
201 /* These are used to accept or reject an incoming call when the status
203 GtkWidget *incoming_call_dialog;
204 TpCallChannel *pending_channel;
205 TpChannelDispatchOperation *pending_cdo;
206 TpAddDispatchOperationContext *pending_context;
208 gulong video_output_motion_handler_id;
209 guint bus_message_source_id;
211 GtkWidget *dtmf_panel;
214 GtkWidget *details_vbox;
215 GtkWidget *vcodec_encoding_label;
216 GtkWidget *acodec_encoding_label;
217 GtkWidget *vcodec_decoding_label;
218 GtkWidget *acodec_decoding_label;
220 GtkWidget *audio_remote_candidate_label;
221 GtkWidget *audio_local_candidate_label;
222 GtkWidget *video_remote_candidate_label;
223 GtkWidget *video_local_candidate_label;
224 GtkWidget *video_remote_candidate_info_img;
225 GtkWidget *video_local_candidate_info_img;
226 GtkWidget *audio_remote_candidate_info_img;
227 GtkWidget *audio_local_candidate_info_img;
229 GstElement *video_input;
230 GstElement *video_preview_sink;
231 GstElement *video_output_sink;
232 GstElement *audio_input;
233 GstElement *audio_output;
234 gboolean audio_output_added;
235 GstElement *pipeline;
236 GstElement *video_tee;
246 gboolean call_started;
247 gboolean sending_video;
248 CameraState camera_state;
250 EmpathyCallWindowFullscreen *fullscreen;
251 gboolean is_fullscreen;
256 guint inactivity_src;
258 /* Those fields represent the state of the window before it actually was in
260 gboolean dialpad_was_visible_before_fs;
261 gint original_width_before_fs;
262 gint original_height_before_fs;
264 gint x, y, w, h, dialpad_width;
267 /* TRUE if the call should be started when the pipeline is playing */
268 gboolean start_call_when_playing;
269 /* TRUE if we requested to set the pipeline in the playing state */
270 gboolean pipeline_playing;
272 EmpathySoundManager *sound_mgr;
275 EmpathyMicMenu *mic_menu;
276 EmpathyCameraMenu *camera_menu;
279 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
281 static void empathy_call_window_realized_cb (GtkWidget *widget,
282 EmpathyCallWindow *window);
284 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
285 GdkEvent *event, EmpathyCallWindow *window);
287 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
288 GdkEventWindowState *event, EmpathyCallWindow *window);
290 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
293 static void empathy_call_window_hangup_cb (gpointer object,
294 EmpathyCallWindow *window);
296 static void empathy_call_window_fullscreen_cb (gpointer object,
297 EmpathyCallWindow *window);
299 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
301 static gboolean empathy_call_window_video_button_press_cb (
302 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
304 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
305 GdkEventKey *event, EmpathyCallWindow *window);
307 static gboolean empathy_call_window_video_output_motion_notify (
308 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
310 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
313 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
315 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
316 EmpathyCallWindow *window);
318 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
320 static void empathy_call_window_status_message (EmpathyCallWindow *window,
323 static gboolean empathy_call_window_bus_message (GstBus *bus,
324 GstMessage *message, gpointer user_data);
327 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
330 gtk_widget_set_visible (self->priv->hangup_button, show);
331 gtk_widget_set_visible (self->priv->audio_call_button, !show);
332 gtk_widget_set_visible (self->priv->video_call_button, !show);
336 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
337 EmpathyCallWindow *self)
339 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
340 empathy_call_window_restart_call (self);
344 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
345 EmpathyCallWindow *self)
347 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
348 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
349 empathy_call_window_restart_call (self);
353 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
355 EmpathyCallWindow *self)
360 g_object_get (self->priv->handler, "call-channel", &call, NULL);
362 tones[0] = tp_dtmf_event_to_char (event);
364 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
366 g_object_unref (call);
370 empathy_call_window_raise_actors (EmpathyCallWindow *self)
372 clutter_actor_raise_top (self->priv->floating_toolbar);
374 clutter_actor_raise_top (self->priv->preview_rectangle1);
375 clutter_actor_raise_top (self->priv->preview_rectangle2);
376 clutter_actor_raise_top (self->priv->preview_rectangle3);
377 clutter_actor_raise_top (self->priv->preview_rectangle4);
381 empathy_call_window_show_video_output (EmpathyCallWindow *self,
384 if (self->priv->video_output != NULL)
385 g_object_set (self->priv->video_output, "visible", show, NULL);
387 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
389 empathy_call_window_raise_actors (self);
393 create_video_output_widget (EmpathyCallWindow *self)
395 EmpathyCallWindowPriv *priv = GET_PRIV (self);
397 g_assert (priv->video_output == NULL);
398 g_assert (priv->pipeline != NULL);
400 priv->video_output = clutter_texture_new ();
402 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
405 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
406 if (priv->video_output_sink == NULL)
407 g_error ("Missing cluttersink");
409 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
411 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
414 gtk_widget_add_events (priv->video_container,
415 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
416 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
417 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
421 create_video_input (EmpathyCallWindow *self)
423 EmpathyCallWindowPriv *priv = GET_PRIV (self);
425 g_assert (priv->video_input == NULL);
426 priv->video_input = empathy_video_src_new ();
427 gst_object_ref (priv->video_input);
428 gst_object_sink (priv->video_input);
432 audio_control_volume_to_element (GBinding *binding,
433 const GValue *source_value,
434 GValue *target_value,
437 /* AudioControl volume is 0-255, with -1 for unknown */
440 hv = g_value_get_int (source_value);
445 g_value_set_double (target_value, hv/255.0);
451 element_volume_to_audio_control (GBinding *binding,
452 const GValue *source_value,
453 GValue *target_value,
458 ev = g_value_get_double (source_value);
459 ev = CLAMP (ev, 0.0, 1.0);
461 g_value_set_int (target_value, ev * 255);
466 create_audio_input (EmpathyCallWindow *self)
468 EmpathyCallWindowPriv *priv = GET_PRIV (self);
470 g_assert (priv->audio_input == NULL);
471 priv->audio_input = empathy_audio_src_new ();
472 gst_object_ref (priv->audio_input);
473 gst_object_sink (priv->audio_input);
475 g_object_bind_property (priv->mic_button, "active",
476 priv->audio_input, "mute",
477 G_BINDING_BIDIRECTIONAL |
478 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
482 add_video_preview_to_pipeline (EmpathyCallWindow *self)
484 EmpathyCallWindowPriv *priv = GET_PRIV (self);
487 g_assert (priv->video_preview != NULL);
488 g_assert (priv->pipeline != NULL);
489 g_assert (priv->video_input != NULL);
490 g_assert (priv->video_tee != NULL);
492 preview = priv->video_preview_sink;
494 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
496 g_warning ("Could not add video input to pipeline");
500 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
502 g_warning ("Could not add video preview to pipeline");
506 if (!gst_element_link (priv->video_input, priv->video_tee))
508 g_warning ("Could not link video input to video tee");
512 if (!gst_element_link (priv->video_tee, preview))
514 g_warning ("Could not link video tee to video preview");
520 empathy_call_window_disable_camera_cb (GtkAction *action,
521 EmpathyCallWindow *self)
523 clutter_actor_destroy (self->priv->preview_hidden_button);
525 gtk_toggle_tool_button_set_active (
526 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
530 empathy_call_window_minimise_camera_cb (GtkAction *action,
531 EmpathyCallWindow *self)
533 clutter_actor_hide (self->priv->video_preview);
534 clutter_actor_show (self->priv->preview_hidden_button);
538 empathy_call_window_maximise_camera_cb (GtkAction *action,
539 EmpathyCallWindow *self)
541 clutter_actor_show (self->priv->video_preview);
542 clutter_actor_hide (self->priv->preview_hidden_button);
546 empathy_call_window_swap_camera_cb (GtkAction *action,
547 EmpathyCallWindow *self)
549 const GList *cameras, *l;
552 DEBUG ("Swapping the camera");
554 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
555 current_cam = empathy_video_src_dup_device (
556 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
558 for (l = cameras; l != NULL; l = l->next)
560 EmpathyCamera *camera = l->data;
562 if (!tp_strdiff (camera->device, current_cam))
567 next = l->next->data;
569 next = cameras->data;
571 /* EmpathyCameraMenu will update itself and do the actual change
573 g_settings_set_string (self->priv->settings,
574 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
581 g_free (current_cam);
585 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
586 EmpathyCamera *camera,
587 EmpathyCallWindow *self)
589 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
591 gtk_action_set_visible (self->priv->menu_swap_camera,
592 g_list_length ((GList *) cameras) >= 2);
596 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
597 EmpathyCamera *camera,
598 EmpathyCallWindow *self)
600 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
602 gtk_action_set_visible (self->priv->menu_swap_camera,
603 g_list_length ((GList *) cameras) >= 2);
607 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
608 EmpathyCallWindow *self)
612 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
614 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
615 0, gtk_get_current_event_time ());
616 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
620 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
621 EmpathyCallWindow *self)
625 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
626 "/preview-hidden-menu");
627 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
628 0, gtk_get_current_event_time ());
629 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
632 static ClutterActor *
633 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
634 ClutterBinAlignment x,
635 ClutterBinAlignment y)
637 ClutterActor *rectangle;
639 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
640 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
641 PREVIEW_ROUND_FACTOR));
643 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
645 clutter_actor_hide (rectangle);
651 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
655 self->priv->preview_layout = clutter_bin_layout_new (
656 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
657 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
659 clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (self->priv->overlay_layout),
660 box, TRUE, TRUE, TRUE,
661 CLUTTER_BOX_ALIGNMENT_CENTER, CLUTTER_BOX_ALIGNMENT_START);
663 self->priv->preview_rectangle1 =
664 empathy_call_window_create_preview_rectangle (self,
665 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
666 self->priv->preview_rectangle2 =
667 empathy_call_window_create_preview_rectangle (self,
668 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
669 self->priv->preview_rectangle3 =
670 empathy_call_window_create_preview_rectangle (self,
671 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
672 self->priv->preview_rectangle4 =
673 empathy_call_window_create_preview_rectangle (self,
674 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
678 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
681 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
682 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
683 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
684 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
688 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
693 guint ret_x = 0, ret_y = 0;
696 if (!clutter_actor_has_allocation (self->priv->preview_box))
699 clutter_actor_get_geometry (self->priv->preview_box, &box);
703 case PREVIEW_POS_TOP_LEFT:
704 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
706 case PREVIEW_POS_TOP_RIGHT:
707 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
708 - SELF_VIDEO_SECTION_WIDTH;
709 ret_y = SELF_VIDEO_SECTION_MARGIN;
711 case PREVIEW_POS_BOTTOM_LEFT:
712 ret_x = SELF_VIDEO_SECTION_MARGIN;
713 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
714 - SELF_VIDEO_SECTION_HEIGHT;
716 case PREVIEW_POS_BOTTOM_RIGHT:
717 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
718 - SELF_VIDEO_SECTION_WIDTH;
719 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
720 - SELF_VIDEO_SECTION_HEIGHT;
723 g_warn_if_reached ();
734 static PreviewPosition
735 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
740 PreviewPosition pos = PREVIEW_POS_NONE;
742 if (!clutter_actor_has_allocation (self->priv->preview_box))
745 clutter_actor_get_geometry (self->priv->preview_box, &box);
747 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
748 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
749 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
750 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
752 pos = PREVIEW_POS_TOP_LEFT;
754 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
755 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
756 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
757 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
759 pos = PREVIEW_POS_TOP_RIGHT;
761 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
762 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
763 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
764 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
766 pos = PREVIEW_POS_BOTTOM_LEFT;
768 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
769 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
770 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
771 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
773 pos = PREVIEW_POS_BOTTOM_RIGHT;
779 static ClutterActor *
780 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
783 ClutterActor *rectangle;
787 case PREVIEW_POS_TOP_LEFT:
788 rectangle = self->priv->preview_rectangle1;
790 case PREVIEW_POS_TOP_RIGHT:
791 rectangle = self->priv->preview_rectangle3;
793 case PREVIEW_POS_BOTTOM_LEFT:
794 rectangle = self->priv->preview_rectangle2;
796 case PREVIEW_POS_BOTTOM_RIGHT:
797 rectangle = self->priv->preview_rectangle4;
807 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
810 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
812 DEBUG ("moving the video preview to %d", pos);
814 self->priv->preview_pos = pos;
818 case PREVIEW_POS_TOP_LEFT:
819 clutter_bin_layout_set_alignment (layout,
820 self->priv->video_preview,
821 CLUTTER_BIN_ALIGNMENT_START,
822 CLUTTER_BIN_ALIGNMENT_START);
824 case PREVIEW_POS_TOP_RIGHT:
825 clutter_bin_layout_set_alignment (layout,
826 self->priv->video_preview,
827 CLUTTER_BIN_ALIGNMENT_END,
828 CLUTTER_BIN_ALIGNMENT_START);
830 case PREVIEW_POS_BOTTOM_LEFT:
831 clutter_bin_layout_set_alignment (layout,
832 self->priv->video_preview,
833 CLUTTER_BIN_ALIGNMENT_START,
834 CLUTTER_BIN_ALIGNMENT_END);
836 case PREVIEW_POS_BOTTOM_RIGHT:
837 clutter_bin_layout_set_alignment (layout,
838 self->priv->video_preview,
839 CLUTTER_BIN_ALIGNMENT_END,
840 CLUTTER_BIN_ALIGNMENT_END);
843 g_warn_if_reached ();
846 g_settings_set_enum (self->priv->settings, "camera-position", pos);
850 _clutter_color_from_rgba (ClutterColor *color,
853 color->red = (guint8) floor (rgba->red * 255);
854 color->green = (guint8) floor (rgba->green * 255);
855 color->blue = (guint8) floor (rgba->blue * 255);
856 color->alpha = (guint8) floor (rgba->alpha * 255);
860 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
863 ClutterActor *rectangle;
864 GtkStyleContext *context;
866 ClutterColor color, highlight;
868 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
869 context = gtk_widget_get_style_context (GTK_WIDGET (self));
870 gtk_style_context_get_color (context, 0, &rgba);
872 _clutter_color_from_rgba (&color, &rgba);
873 clutter_color_shade (&color, 1.4, &highlight);
875 empathy_rounded_rectangle_set_border_width (
876 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
877 empathy_rounded_rectangle_set_border_color (
878 EMPATHY_ROUNDED_RECTANGLE (rectangle), &highlight);
882 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
883 ClutterActor *rectangle)
885 GtkStyleContext *context;
887 ClutterColor color, darker;
889 context = gtk_widget_get_style_context (GTK_WIDGET (self));
890 gtk_style_context_get_background_color (context, 0, &rgba);
892 _clutter_color_from_rgba (&color, &rgba);
893 clutter_color_shade (&color, 0.55, &darker);
895 empathy_rounded_rectangle_set_border_width (
896 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
897 empathy_rounded_rectangle_set_border_color (
898 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
902 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
904 ClutterActor *rectangle;
906 rectangle = empathy_call_window_get_preview_rectangle (self,
907 self->priv->preview_pos);
909 /* We don't want to darken the rectangle where the preview
912 if (self->priv->preview_rectangle1 != rectangle)
913 empathy_call_window_darken_preview_rectangle (self,
914 self->priv->preview_rectangle1);
916 if (self->priv->preview_rectangle2 != rectangle)
917 empathy_call_window_darken_preview_rectangle (self,
918 self->priv->preview_rectangle2);
920 if (self->priv->preview_rectangle3 != rectangle)
921 empathy_call_window_darken_preview_rectangle (self,
922 self->priv->preview_rectangle3);
924 if (self->priv->preview_rectangle4 != rectangle)
925 empathy_call_window_darken_preview_rectangle (self,
926 self->priv->preview_rectangle4);
930 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
934 ClutterModifierType modifiers,
935 EmpathyCallWindow *self)
937 ClutterActor *stage = clutter_actor_get_stage (actor);
940 self->priv->drag_preview = clutter_clone_new (actor);
942 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
943 self->priv->drag_preview);
945 clutter_actor_transform_stage_point (actor, event_x, event_y,
948 clutter_actor_set_position (self->priv->drag_preview,
949 event_x - rel_x, event_y - rel_y);
951 clutter_drag_action_set_drag_handle (action,
952 self->priv->drag_preview);
954 clutter_actor_set_opacity (actor, 0);
955 clutter_actor_hide (self->priv->preview_shown_button);
957 empathy_call_window_show_preview_rectangles (self, TRUE);
958 empathy_call_window_darken_preview_rectangles (self);
962 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
965 clutter_actor_set_opacity (actor, 255);
969 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
973 ClutterModifierType modifiers,
974 EmpathyCallWindow *self)
979 /* Get the position before destroying the drag actor, otherwise the
980 * preview_box allocation won't be valid and we won't be able to
981 * calculate the position. */
982 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
984 empathy_call_window_get_preview_coordinates (self,
985 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
988 /* Move the preview to the destination and destroy it afterwards */
989 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
992 "signal-swapped-after::completed",
993 clutter_actor_destroy, self->priv->drag_preview,
994 "signal-swapped-after::completed",
995 clutter_actor_show, self->priv->preview_shown_button,
997 empathy_call_window_on_animation_completed_cb, actor,
1000 self->priv->drag_preview = NULL;
1002 if (pos != PREVIEW_POS_NONE)
1003 empathy_call_window_move_video_preview (self, pos);
1005 empathy_call_window_show_preview_rectangles (self, FALSE);
1009 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1010 ClutterActor *actor,
1013 EmpathyCallWindow *self)
1015 PreviewPosition pos;
1016 gfloat event_x, event_y;
1018 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1020 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1022 if (pos != PREVIEW_POS_NONE)
1023 empathy_call_window_highlight_preview_rectangle (self, pos);
1025 empathy_call_window_darken_preview_rectangles (self);
1029 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1030 ClutterCrossingEvent *event,
1031 EmpathyCallWindow *self)
1033 ClutterActor *rectangle;
1035 rectangle = empathy_call_window_get_preview_rectangle (self,
1036 self->priv->preview_pos);
1038 empathy_call_window_highlight_preview_rectangle (self,
1039 self->priv->preview_pos);
1041 clutter_actor_show (rectangle);
1047 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1048 ClutterCrossingEvent *event,
1049 EmpathyCallWindow *self)
1051 ClutterActor *rectangle;
1053 rectangle = empathy_call_window_get_preview_rectangle (self,
1054 self->priv->preview_pos);
1056 empathy_call_window_darken_preview_rectangle (self, rectangle);
1058 clutter_actor_hide (rectangle);
1064 create_video_preview (EmpathyCallWindow *self)
1066 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1067 ClutterLayoutManager *layout;
1068 ClutterActor *preview;
1070 ClutterAction *action;
1072 PreviewPosition pos;
1073 GdkRGBA transparent = { 0., 0., 0., 0. };
1076 g_assert (priv->video_preview == NULL);
1078 pos = g_settings_get_enum (priv->settings, "camera-position");
1080 preview = empathy_rounded_texture_new ();
1081 clutter_actor_set_size (preview,
1082 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1084 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1085 if (priv->video_preview_sink == NULL)
1086 g_error ("Missing cluttersink, check your clutter-gst installation");
1087 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1088 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1090 /* Add a little offset to the video preview */
1091 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1092 CLUTTER_BIN_ALIGNMENT_CENTER);
1093 priv->video_preview = clutter_box_new (layout);
1094 clutter_actor_set_size (priv->video_preview,
1095 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1096 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1098 /* Spinner for when changing the camera device */
1099 priv->preview_spinner_widget = gtk_spinner_new ();
1100 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1102 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1103 gtk_widget_override_background_color (
1104 gtk_clutter_actor_get_widget (
1105 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor)),
1106 GTK_STATE_FLAG_NORMAL, &transparent);
1107 gtk_widget_show (priv->preview_spinner_widget);
1110 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1111 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1112 priv->preview_spinner_widget);
1113 clutter_actor_set_size (priv->preview_spinner_actor,
1114 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1115 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1116 clutter_actor_hide (priv->preview_spinner_actor);
1118 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1120 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1121 priv->preview_spinner_actor);
1123 g_object_set (priv->video_preview_sink,
1128 /* Translators: this is an "Info" label. It should be as short
1130 button = gtk_button_new_with_label (_("i"));
1131 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (button);
1132 clutter_actor_set_size (b, 24, 24);
1133 clutter_actor_set_margin_right (b, 4);
1134 clutter_actor_set_margin_bottom (b, 2);
1135 bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b));
1136 gtk_widget_override_background_color (bin, GTK_STATE_FLAG_NORMAL, &transparent);
1138 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1139 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1141 g_signal_connect (button, "clicked",
1142 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1145 /* Translators: this is an "Info" label. It should be as short
1147 button = gtk_button_new_with_label (_("i"));
1148 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (button);
1149 clutter_actor_set_size (b, 24, 24);
1150 gtk_widget_override_background_color (bin, GTK_STATE_FLAG_NORMAL, &transparent);
1152 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1153 priv->preview_hidden_button,
1154 CLUTTER_BIN_ALIGNMENT_START,
1155 CLUTTER_BIN_ALIGNMENT_END);
1157 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1159 clutter_actor_hide (priv->preview_hidden_button);
1161 g_signal_connect (button, "clicked",
1162 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1165 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1166 priv->video_preview,
1167 CLUTTER_BIN_ALIGNMENT_START,
1168 CLUTTER_BIN_ALIGNMENT_END);
1170 empathy_call_window_move_video_preview (self, pos);
1172 action = clutter_drag_action_new ();
1173 g_signal_connect (action, "drag-begin",
1174 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1175 g_signal_connect (action, "drag-end",
1176 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1177 g_signal_connect (action, "drag-motion",
1178 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1180 g_signal_connect (preview, "enter-event",
1181 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1182 g_signal_connect (preview, "leave-event",
1183 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1185 clutter_actor_add_action (preview, action);
1186 clutter_actor_set_reactive (preview, TRUE);
1187 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1191 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1193 clutter_actor_show (self->priv->preview_spinner_actor);
1194 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1198 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1200 clutter_actor_hide (self->priv->preview_spinner_actor);
1201 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1205 empathy_call_window_play_camera (EmpathyCallWindow *self,
1208 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1209 GstElement *preview;
1212 if (priv->video_preview == NULL)
1214 create_video_preview (self);
1215 add_video_preview_to_pipeline (self);
1220 state = GST_STATE_PLAYING;
1224 empathy_call_window_start_camera_spinning (self);
1225 state = GST_STATE_NULL;
1228 preview = priv->video_preview_sink;
1230 gst_element_set_state (preview, state);
1231 gst_element_set_state (priv->video_tee, state);
1232 gst_element_set_state (priv->video_input, state);
1236 display_video_preview (EmpathyCallWindow *self,
1239 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1241 if (priv->video_preview == NULL)
1243 create_video_preview (self);
1244 add_video_preview_to_pipeline (self);
1249 /* Display the video preview */
1250 DEBUG ("Show video preview");
1252 empathy_call_window_play_camera (self, TRUE);
1253 clutter_actor_show (priv->video_preview);
1254 clutter_actor_raise_top (priv->floating_toolbar);
1258 /* Hide the video preview */
1259 DEBUG ("Hide video preview");
1261 if (priv->video_preview != NULL)
1263 clutter_actor_hide (priv->video_preview);
1264 empathy_call_window_play_camera (self, FALSE);
1270 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1272 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1274 empathy_call_window_status_message (window, _("Connecting…"));
1275 priv->call_state = CONNECTING;
1277 /* Show the toolbar */
1278 clutter_state_set_state (priv->transitions, "fade-in");
1281 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1282 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1286 disable_camera (EmpathyCallWindow *self)
1288 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1290 if (priv->camera_state == CAMERA_STATE_OFF)
1293 DEBUG ("Disable camera");
1295 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1297 priv->camera_state = CAMERA_STATE_OFF;
1301 enable_camera (EmpathyCallWindow *self)
1303 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1305 if (priv->camera_state == CAMERA_STATE_ON)
1308 if (priv->video_input == NULL)
1310 DEBUG ("Can't enable camera, no input");
1314 DEBUG ("Enable camera");
1316 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1318 priv->camera_state = CAMERA_STATE_ON;
1322 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1323 EmpathyCallWindow *self)
1325 if (gtk_toggle_tool_button_get_active (toggle))
1326 enable_camera (self);
1328 disable_camera (self);
1332 create_pipeline (EmpathyCallWindow *self)
1334 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1337 g_assert (priv->pipeline == NULL);
1339 priv->pipeline = gst_pipeline_new (NULL);
1340 priv->pipeline_playing = FALSE;
1342 priv->video_tee = gst_element_factory_make ("tee", NULL);
1343 gst_object_ref (priv->video_tee);
1344 gst_object_sink (priv->video_tee);
1346 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1348 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1349 priv->bus_message_source_id = gst_bus_add_watch (bus,
1350 empathy_call_window_bus_message, self);
1352 g_object_unref (bus);
1356 empathy_call_window_settings_cb (GtkAction *action,
1357 EmpathyCallWindow *self)
1359 gchar *args = g_strdup_printf ("-p %s",
1360 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1362 empathy_launch_program (BIN_DIR, "empathy", args);
1368 empathy_call_window_contents_cb (GtkAction *action,
1369 EmpathyCallWindow *self)
1371 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1375 empathy_call_window_debug_cb (GtkAction *action,
1376 EmpathyCallWindow *self)
1378 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1382 empathy_call_window_about_cb (GtkAction *action,
1383 EmpathyCallWindow *self)
1385 empathy_about_dialog_new (GTK_WINDOW (self));
1389 empathy_call_window_toolbar_timeout (gpointer data)
1391 EmpathyCallWindow *self = data;
1393 /* We don't want to hide the toolbar if we're not in a call, as
1394 * to show the call status all the time. */
1395 if (self->priv->call_state != CONNECTING &&
1396 self->priv->call_state != DISCONNECTED)
1397 clutter_state_set_state (self->priv->transitions, "fade-out");
1403 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1405 EmpathyCallWindow *self)
1407 clutter_state_set_state (self->priv->transitions, "fade-in");
1409 if (self->priv->inactivity_src > 0)
1410 g_source_remove (self->priv->inactivity_src);
1412 self->priv->inactivity_src = g_timeout_add_seconds (3,
1413 empathy_call_window_toolbar_timeout, self);
1419 empathy_call_window_configure_event_cb (GtkWidget *widget,
1421 EmpathyCallWindow *self)
1423 GdkWindow *gdk_window;
1424 GdkWindowState window_state;
1426 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1427 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1429 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1430 &self->priv->dialpad_width, NULL);
1432 gdk_window = gtk_widget_get_window (widget);
1433 window_state = gdk_window_get_state (gdk_window);
1434 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1440 empathy_call_window_destroyed_cb (GtkWidget *object,
1441 EmpathyCallWindow *self)
1443 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1445 /* Save the geometry as if the dialpad was hidden. */
1446 empathy_geometry_save_values (GTK_WINDOW (self),
1447 self->priv->x, self->priv->y,
1448 self->priv->w - self->priv->dialpad_width, self->priv->h,
1449 self->priv->maximized);
1454 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1456 EmpathyCallWindow *self)
1458 switch (response_id)
1460 case GTK_RESPONSE_ACCEPT:
1461 tp_channel_dispatch_operation_handle_with_async (
1462 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1464 tp_clear_object (&self->priv->pending_cdo);
1465 tp_clear_object (&self->priv->pending_channel);
1466 tp_clear_object (&self->priv->pending_context);
1469 case GTK_RESPONSE_CANCEL:
1470 tp_channel_dispatch_operation_close_channels_async (
1471 self->priv->pending_cdo, NULL, NULL);
1473 empathy_call_window_status_message (self, _("Disconnected"));
1474 self->priv->call_state = DISCONNECTED;
1477 g_warn_if_reached ();
1482 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1486 g_assert (self->priv->call_state != CONNECTED);
1488 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1490 empathy_call_window_status_message (self, _("Incoming call"));
1491 self->priv->call_state = RINGING;
1493 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1494 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1495 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1496 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1497 empathy_contact_get_alias (self->priv->contact));
1499 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1500 _("Reject"), GTK_RESPONSE_CANCEL,
1501 _("Answer"), GTK_RESPONSE_ACCEPT,
1504 g_signal_connect (self->priv->incoming_call_dialog, "response",
1505 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1506 gtk_widget_show (self->priv->incoming_call_dialog);
1510 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1514 EmpathyCallWindow *self)
1516 tp_clear_object (&self->priv->pending_cdo);
1517 tp_clear_object (&self->priv->pending_channel);
1518 tp_clear_object (&self->priv->pending_context);
1520 /* We don't know if the incoming call has been accepted or not, so we
1521 * assume it hasn't and if it has, we'll set the proper status when
1522 * we get the new handler. */
1523 empathy_call_window_status_message (self, _("Disconnected"));
1524 self->priv->call_state = DISCONNECTED;
1526 gtk_widget_destroy (self->priv->incoming_call_dialog);
1527 self->priv->incoming_call_dialog = NULL;
1531 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1532 TpCallChannel *channel,
1533 TpChannelDispatchOperation *dispatch_operation,
1534 TpAddDispatchOperationContext *context)
1536 g_assert (self->priv->pending_channel == NULL);
1537 g_assert (self->priv->pending_context == NULL);
1538 g_assert (self->priv->pending_cdo == NULL);
1540 /* Start ringing and delay until the user answers or hangs. */
1541 self->priv->pending_channel = g_object_ref (channel);
1542 self->priv->pending_context = g_object_ref (context);
1543 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1545 g_signal_connect (self->priv->pending_cdo, "invalidated",
1546 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1548 empathy_call_window_set_state_ringing (self);
1549 tp_add_dispatch_operation_context_accept (context);
1553 empathy_call_window_init (EmpathyCallWindow *self)
1555 EmpathyCallWindowPriv *priv;
1557 GtkWidget *top_vbox;
1559 ClutterConstraint *constraint;
1560 ClutterActor *remote_avatar;
1561 GtkStyleContext *context;
1565 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1566 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1568 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1570 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1571 gui = empathy_builder_get_file (filename,
1572 "call_window_vbox", &top_vbox,
1573 "errors_vbox", &priv->errors_vbox,
1574 "pane", &priv->pane,
1575 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1576 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1577 "status_label", &priv->status_label,
1578 "audiocall", &priv->audio_call_button,
1579 "videocall", &priv->video_call_button,
1580 "microphone", &priv->mic_button,
1581 "volume", &priv->volume_button,
1582 "camera", &priv->camera_button,
1583 "hangup", &priv->hangup_button,
1584 "dialpad", &priv->dialpad_button,
1585 "toolbar", &priv->toolbar,
1586 "bottom_toolbar", &priv->bottom_toolbar,
1587 "ui_manager", &priv->ui_manager,
1588 "menufullscreen", &priv->menu_fullscreen,
1589 "menupreviewswap", &priv->menu_swap_camera,
1590 "details_vbox", &priv->details_vbox,
1591 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1592 "acodec_encoding_label", &priv->acodec_encoding_label,
1593 "acodec_decoding_label", &priv->acodec_decoding_label,
1594 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1595 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1596 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1597 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1598 "video_local_candidate_label", &priv->video_local_candidate_label,
1599 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1600 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1601 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1602 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1606 empathy_builder_connect (gui, self,
1607 "hangup", "clicked", empathy_call_window_hangup_cb,
1608 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1609 "videocall", "clicked", empathy_call_window_video_call_cb,
1610 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1611 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1612 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1613 "menusettings", "activate", empathy_call_window_settings_cb,
1614 "menucontents", "activate", empathy_call_window_contents_cb,
1615 "menudebug", "activate", empathy_call_window_debug_cb,
1616 "menuabout", "activate", empathy_call_window_about_cb,
1617 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1618 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1619 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1620 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1623 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1625 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1627 g_object_bind_property (priv->camera_monitor, "available",
1628 priv->camera_button, "sensitive",
1629 G_BINDING_SYNC_CREATE);
1631 g_signal_connect (priv->camera_monitor, "added",
1632 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1633 g_signal_connect (priv->camera_monitor, "removed",
1634 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1636 priv->lock = g_mutex_new ();
1638 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1640 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1641 CONTENT_HBOX_SPACING);
1642 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1643 CONTENT_HBOX_BORDER_WIDTH);
1644 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1647 /* main contents remote avatar/video box */
1648 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1649 CLUTTER_BIN_ALIGNMENT_CENTER);
1651 priv->video_box = clutter_box_new (priv->video_layout);
1653 priv->video_container = gtk_clutter_embed_new ();
1655 gtk_widget_set_size_request (priv->video_container,
1656 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1658 /* Set the background color to that of the rest of the window */
1659 context = gtk_widget_get_style_context (priv->content_hbox);
1660 gtk_style_context_get_background_color (context,
1661 GTK_STATE_FLAG_NORMAL, &rgba);
1662 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1663 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1664 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1665 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1666 clutter_stage_set_color (
1667 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1668 GTK_CLUTTER_EMBED (priv->video_container))),
1671 clutter_container_add (
1672 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1673 GTK_CLUTTER_EMBED (priv->video_container))),
1677 constraint = clutter_bind_constraint_new (
1678 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1679 CLUTTER_BIND_SIZE, 0);
1680 clutter_actor_add_constraint (priv->video_box, constraint);
1682 priv->remote_user_avatar_widget = gtk_image_new ();
1683 remote_avatar = gtk_clutter_actor_new_with_contents (
1684 priv->remote_user_avatar_widget);
1686 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1689 /* create the overlay box */
1690 priv->overlay_layout = clutter_box_layout_new ();
1691 clutter_box_layout_set_vertical (
1692 CLUTTER_BOX_LAYOUT (priv->overlay_layout), TRUE);
1693 priv->overlay_box = clutter_box_new (priv->overlay_layout);
1695 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1697 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1699 empathy_call_window_create_preview_rectangles (self);
1701 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1702 priv->video_container, TRUE, TRUE,
1703 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1705 create_pipeline (self);
1706 create_video_output_widget (self);
1707 create_audio_input (self);
1708 create_video_input (self);
1710 priv->floating_toolbar = empathy_rounded_actor_new (2);
1711 clutter_actor_set_margin_bottom (priv->floating_toolbar, FLOATING_TOOLBAR_SPACING);
1713 gtk_widget_reparent (priv->bottom_toolbar,
1714 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1716 clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (priv->overlay_layout),
1717 priv->floating_toolbar, FALSE, FALSE, FALSE,
1718 CLUTTER_BOX_ALIGNMENT_CENTER, CLUTTER_BOX_ALIGNMENT_END);
1720 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1722 clutter_actor_raise_top (priv->floating_toolbar);
1724 /* Transitions for the floating toolbar */
1725 priv->transitions = clutter_state_new ();
1727 /* all transitions last for 2s */
1728 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1730 /* transition from any state to "fade-out" state */
1731 clutter_state_set (priv->transitions, NULL, "fade-out",
1732 priv->floating_toolbar,
1733 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1736 /* transition from any state to "fade-in" state */
1737 clutter_state_set (priv->transitions, NULL, "fade-in",
1738 priv->floating_toolbar,
1739 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1742 /* put the actor into the "fade-in" state with no animation */
1743 clutter_state_warp_to_state (priv->transitions, "fade-in");
1745 /* The call will be started as soon the pipeline is playing */
1746 priv->start_call_when_playing = TRUE;
1748 priv->dtmf_panel = empathy_dialpad_widget_new ();
1749 g_signal_connect (priv->dtmf_panel, "start-tone",
1750 G_CALLBACK (dtmf_start_tone_cb), self);
1752 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1755 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1758 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1760 gtk_widget_show_all (top_vbox);
1762 gtk_widget_hide (priv->dtmf_panel);
1763 gtk_widget_hide (priv->details_vbox);
1765 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1767 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1768 priv->video_container);
1770 /* We hide the bottom toolbar after 3s of inactivity and show it
1771 * again on mouse movement */
1772 priv->inactivity_src = g_timeout_add_seconds (3,
1773 empathy_call_window_toolbar_timeout, self);
1775 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1776 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1778 g_signal_connect (G_OBJECT (self), "realize",
1779 G_CALLBACK (empathy_call_window_realized_cb), self);
1781 g_signal_connect (G_OBJECT (self), "delete-event",
1782 G_CALLBACK (empathy_call_window_delete_cb), self);
1784 g_signal_connect (G_OBJECT (self), "window-state-event",
1785 G_CALLBACK (empathy_call_window_state_event_cb), self);
1787 g_signal_connect (G_OBJECT (self), "key-press-event",
1788 G_CALLBACK (empathy_call_window_key_press_cb), self);
1790 g_signal_connect (self, "motion-notify-event",
1791 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1793 priv->timer = g_timer_new ();
1795 g_object_ref (priv->ui_manager);
1796 g_object_unref (gui);
1798 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1799 priv->mic_menu = empathy_mic_menu_new (self);
1800 priv->camera_menu = empathy_camera_menu_new (self);
1802 empathy_call_window_show_hangup_button (self, TRUE);
1804 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1805 /* These signals are used to track the window position and save it
1806 * when the window is destroyed. We need to do this as we don't want
1807 * the window geometry to be saved with the dialpad taken into account. */
1808 g_signal_connect (self, "destroy",
1809 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1810 g_signal_connect (self, "configure-event",
1811 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1812 g_signal_connect (self, "window-state-event",
1813 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1815 /* Don't display labels in both toolbars */
1816 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1819 /* Instead of specifying a width and a height, we specify only one size. That's
1820 because we want a square avatar icon. */
1822 init_contact_avatar_with_size (EmpathyContact *contact,
1823 GtkWidget *image_widget,
1826 GdkPixbuf *pixbuf_avatar = NULL;
1828 if (contact != NULL)
1830 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1834 if (pixbuf_avatar == NULL)
1836 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1837 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1840 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1842 if (pixbuf_avatar != NULL)
1843 g_object_unref (pixbuf_avatar);
1847 set_window_title (EmpathyCallWindow *self)
1849 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1852 if (priv->contact != NULL)
1854 /* translators: Call is a noun and %s is the contact name. This string
1855 * is used in the window title */
1856 tmp = g_strdup_printf (_("Call with %s"),
1857 empathy_contact_get_alias (priv->contact));
1858 gtk_window_set_title (GTK_WINDOW (self), tmp);
1863 g_warning ("Unknown remote contact!");
1868 set_remote_user_name (EmpathyCallWindow *self,
1869 EmpathyContact *contact)
1871 const gchar *alias = empathy_contact_get_alias (contact);
1872 const gchar *status = empathy_contact_get_status (contact);
1875 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1876 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1882 contact_name_changed_cb (EmpathyContact *contact,
1884 EmpathyCallWindow *self)
1886 set_window_title (self);
1887 set_remote_user_name (self, contact);
1891 contact_presence_changed_cb (EmpathyContact *contact,
1893 EmpathyCallWindow *self)
1895 set_remote_user_name (self, contact);
1899 contact_avatar_changed_cb (EmpathyContact *contact,
1901 EmpathyCallWindow *self)
1904 GtkAllocation allocation;
1905 GtkWidget *avatar_widget;
1907 avatar_widget = self->priv->remote_user_avatar_widget;
1909 gtk_widget_get_allocation (avatar_widget, &allocation);
1910 size = allocation.height;
1914 /* the widget is not allocated yet, set a default size */
1915 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1916 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1919 init_contact_avatar_with_size (contact, avatar_widget, size);
1921 avatar_widget = self->priv->remote_user_avatar_toolbar;
1923 gtk_widget_get_allocation (avatar_widget, &allocation);
1924 size = allocation.height;
1928 /* the widget is not allocated yet, set a default size */
1929 size = SMALL_TOOLBAR_SIZE;
1932 init_contact_avatar_with_size (contact, avatar_widget, size);
1936 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1937 EmpathyCallHandler *handler)
1939 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1941 tp_g_signal_connect_object (priv->contact, "notify::name",
1942 G_CALLBACK (contact_name_changed_cb), self, 0);
1943 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1944 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1945 tp_g_signal_connect_object (priv->contact, "notify::presence",
1946 G_CALLBACK (contact_presence_changed_cb), self, 0);
1948 set_window_title (self);
1949 set_remote_user_name (self, priv->contact);
1951 init_contact_avatar_with_size (priv->contact,
1952 priv->remote_user_avatar_widget,
1953 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1954 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1956 init_contact_avatar_with_size (priv->contact,
1957 priv->remote_user_avatar_toolbar,
1958 SMALL_TOOLBAR_SIZE);
1960 /* The remote avatar is shown by default and will be hidden when we receive
1961 video from the remote side. */
1962 clutter_actor_hide (priv->video_output);
1963 gtk_widget_show (priv->remote_user_avatar_widget);
1967 update_send_codec (EmpathyCallWindow *self,
1970 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1977 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1978 widget = priv->acodec_encoding_label;
1982 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1983 widget = priv->vcodec_encoding_label;
1989 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1990 gtk_label_set_text (GTK_LABEL (widget), tmp);
1995 send_audio_codec_notify_cb (GObject *object,
1999 EmpathyCallWindow *self = user_data;
2001 update_send_codec (self, TRUE);
2005 send_video_codec_notify_cb (GObject *object,
2009 EmpathyCallWindow *self = user_data;
2011 update_send_codec (self, FALSE);
2015 update_recv_codec (EmpathyCallWindow *self,
2018 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2021 GString *str = NULL;
2025 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2026 widget = priv->acodec_decoding_label;
2030 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2031 widget = priv->vcodec_decoding_label;
2037 for (l = codecs; l != NULL; l = g_list_next (l))
2039 FsCodec *codec = l->data;
2042 str = g_string_new (NULL);
2044 g_string_append (str, ", ");
2046 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2050 gtk_label_set_text (GTK_LABEL (widget), str->str);
2051 g_string_free (str, TRUE);
2055 recv_audio_codecs_notify_cb (GObject *object,
2059 EmpathyCallWindow *self = user_data;
2061 update_recv_codec (self, TRUE);
2065 recv_video_codecs_notify_cb (GObject *object,
2069 EmpathyCallWindow *self = user_data;
2071 update_recv_codec (self, FALSE);
2074 static const gchar *
2075 candidate_type_to_str (FsCandidate *candidate)
2077 switch (candidate->type)
2079 case FS_CANDIDATE_TYPE_HOST:
2081 case FS_CANDIDATE_TYPE_SRFLX:
2082 return "server reflexive";
2083 case FS_CANDIDATE_TYPE_PRFLX:
2084 return "peer reflexive";
2085 case FS_CANDIDATE_TYPE_RELAY:
2087 case FS_CANDIDATE_TYPE_MULTICAST:
2094 static const gchar *
2095 candidate_type_to_desc (FsCandidate *candidate)
2097 switch (candidate->type)
2099 case FS_CANDIDATE_TYPE_HOST:
2100 return _("The IP address as seen by the machine");
2101 case FS_CANDIDATE_TYPE_SRFLX:
2102 return _("The IP address as seen by a server on the Internet");
2103 case FS_CANDIDATE_TYPE_PRFLX:
2104 return _("The IP address of the peer as seen by the other side");
2105 case FS_CANDIDATE_TYPE_RELAY:
2106 return _("The IP address of a relay server");
2107 case FS_CANDIDATE_TYPE_MULTICAST:
2108 return _("The IP address of the multicast group");
2115 update_candidat_widget (EmpathyCallWindow *self,
2118 FsCandidate *candidate)
2122 g_assert (candidate != NULL);
2123 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2124 candidate->port, candidate_type_to_str (candidate));
2126 gtk_label_set_text (GTK_LABEL (label), str);
2127 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2133 candidates_changed_cb (GObject *object,
2135 EmpathyCallWindow *self)
2137 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2138 FsCandidate *candidate = NULL;
2140 if (type == FS_MEDIA_TYPE_VIDEO)
2142 /* Update remote candidate */
2143 candidate = empathy_call_handler_get_video_remote_candidate (
2146 update_candidat_widget (self, priv->video_remote_candidate_label,
2147 priv->video_remote_candidate_info_img, candidate);
2149 /* Update local candidate */
2150 candidate = empathy_call_handler_get_video_local_candidate (
2153 update_candidat_widget (self, priv->video_local_candidate_label,
2154 priv->video_local_candidate_info_img, candidate);
2158 /* Update remote candidate */
2159 candidate = empathy_call_handler_get_audio_remote_candidate (
2162 update_candidat_widget (self, priv->audio_remote_candidate_label,
2163 priv->audio_remote_candidate_info_img, candidate);
2165 /* Update local candidate */
2166 candidate = empathy_call_handler_get_audio_local_candidate (
2169 update_candidat_widget (self, priv->audio_local_candidate_label,
2170 priv->audio_local_candidate_info_img, candidate);
2175 empathy_call_window_constructed (GObject *object)
2177 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2178 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2179 TpCallChannel *call;
2182 g_assert (priv->handler != NULL);
2184 g_object_get (priv->handler, "call-channel", &call, NULL);
2185 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2186 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2187 tp_clear_object (&call);
2189 priv->contact = empathy_call_handler_get_contact (priv->handler);
2190 g_assert (priv->contact != NULL);
2191 g_object_ref (priv->contact);
2193 if (!empathy_contact_can_voip_video (priv->contact))
2195 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2196 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2199 empathy_call_window_setup_avatars (self, priv->handler);
2200 empathy_call_window_set_state_connecting (self);
2202 if (!empathy_call_handler_has_initial_video (priv->handler))
2204 gtk_toggle_tool_button_set_active (
2205 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2207 /* If call has InitialVideo, the preview will be started once the call has
2208 * been started (start_call()). */
2210 update_send_codec (self, TRUE);
2211 update_send_codec (self, FALSE);
2212 update_recv_codec (self, TRUE);
2213 update_recv_codec (self, FALSE);
2215 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2216 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2217 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2218 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2219 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2220 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2221 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2222 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2224 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2225 G_CALLBACK (candidates_changed_cb), self, 0);
2228 static void empathy_call_window_dispose (GObject *object);
2229 static void empathy_call_window_finalize (GObject *object);
2232 empathy_call_window_set_property (GObject *object,
2233 guint property_id, const GValue *value, GParamSpec *pspec)
2235 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2237 switch (property_id)
2239 case PROP_CALL_HANDLER:
2240 priv->handler = g_value_dup_object (value);
2243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2248 empathy_call_window_get_property (GObject *object,
2249 guint property_id, GValue *value, GParamSpec *pspec)
2251 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2253 switch (property_id)
2255 case PROP_CALL_HANDLER:
2256 g_value_set_object (value, priv->handler);
2259 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2264 empathy_call_window_class_init (
2265 EmpathyCallWindowClass *empathy_call_window_class)
2267 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2268 GParamSpec *param_spec;
2270 g_type_class_add_private (empathy_call_window_class,
2271 sizeof (EmpathyCallWindowPriv));
2273 object_class->constructed = empathy_call_window_constructed;
2274 object_class->set_property = empathy_call_window_set_property;
2275 object_class->get_property = empathy_call_window_get_property;
2277 object_class->dispose = empathy_call_window_dispose;
2278 object_class->finalize = empathy_call_window_finalize;
2280 param_spec = g_param_spec_object ("handler",
2281 "handler", "The call handler",
2282 EMPATHY_TYPE_CALL_HANDLER,
2283 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2284 g_object_class_install_property (object_class,
2285 PROP_CALL_HANDLER, param_spec);
2289 empathy_call_window_dispose (GObject *object)
2291 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2292 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2294 if (priv->dispose_has_run)
2297 priv->dispose_has_run = TRUE;
2299 if (priv->handler != NULL)
2301 empathy_call_handler_stop_call (priv->handler);
2302 tp_clear_object (&priv->handler);
2305 if (priv->bus_message_source_id != 0)
2307 g_source_remove (priv->bus_message_source_id);
2308 priv->bus_message_source_id = 0;
2311 if (priv->got_video_src > 0)
2313 g_source_remove (priv->got_video_src);
2314 priv->got_video_src = 0;
2317 if (priv->inactivity_src > 0)
2319 g_source_remove (priv->inactivity_src);
2320 priv->inactivity_src = 0;
2323 tp_clear_object (&priv->pipeline);
2324 tp_clear_object (&priv->video_input);
2325 tp_clear_object (&priv->audio_input);
2326 tp_clear_object (&priv->video_tee);
2327 tp_clear_object (&priv->ui_manager);
2328 tp_clear_object (&priv->fullscreen);
2329 tp_clear_object (&priv->camera_monitor);
2330 tp_clear_object (&priv->settings);
2331 tp_clear_object (&priv->sound_mgr);
2332 tp_clear_object (&priv->mic_menu);
2333 tp_clear_object (&priv->camera_menu);
2334 tp_clear_object (&priv->transitions);
2336 g_list_free_full (priv->notifiers, g_object_unref);
2338 if (priv->timer_id != 0)
2339 g_source_remove (priv->timer_id);
2342 tp_clear_object (&priv->contact);
2344 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2348 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2350 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2352 if (priv->video_output_motion_handler_id != 0)
2354 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2355 priv->video_output_motion_handler_id);
2356 priv->video_output_motion_handler_id = 0;
2361 empathy_call_window_finalize (GObject *object)
2363 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2364 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2366 disconnect_video_output_motion_handler (self);
2368 /* free any data held directly by the object here */
2369 g_mutex_free (priv->lock);
2371 g_timer_destroy (priv->timer);
2373 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2378 empathy_call_window_new (EmpathyCallHandler *handler)
2380 return EMPATHY_CALL_WINDOW (
2381 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2385 empathy_call_window_present (EmpathyCallWindow *self,
2386 EmpathyCallHandler *handler)
2388 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2390 empathy_window_present (GTK_WINDOW (self));
2392 if (self->priv->call_state == DISCONNECTED)
2394 /* start a new call if one is not already in progress */
2395 tp_clear_object (&self->priv->handler);
2396 self->priv->handler = g_object_ref (handler);
2397 empathy_call_window_connect_handler (self);
2399 empathy_call_window_restart_call (self);
2404 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2405 GstElement *conference, gpointer user_data)
2407 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2408 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2409 FsElementAddedNotifier *notifier;
2412 DEBUG ("Conference added");
2414 /* Add notifier to set the various element properties as needed */
2415 notifier = fs_element_added_notifier_new ();
2416 keyfile = fs_utils_get_default_element_properties (conference);
2418 if (keyfile != NULL)
2419 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2421 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2423 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2425 gst_bin_add (GST_BIN (priv->pipeline), conference);
2426 gst_element_set_state (conference, GST_STATE_PLAYING);
2430 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2431 GstElement *conference, gpointer user_data)
2433 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2434 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2436 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2437 gst_element_set_state (conference, GST_STATE_NULL);
2441 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2443 GstStateChangeReturn state_change_return;
2444 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2446 if (priv->pipeline == NULL)
2449 if (priv->bus_message_source_id != 0)
2451 g_source_remove (priv->bus_message_source_id);
2452 priv->bus_message_source_id = 0;
2455 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2457 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2458 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2460 if (priv->pipeline != NULL)
2461 g_object_unref (priv->pipeline);
2462 priv->pipeline = NULL;
2464 if (priv->audio_output != NULL)
2465 g_object_unref (priv->audio_output);
2466 priv->audio_output = NULL;
2467 priv->audio_output_added = FALSE;
2469 if (priv->video_tee != NULL)
2470 g_object_unref (priv->video_tee);
2471 priv->video_tee = NULL;
2473 if (priv->video_preview != NULL)
2474 clutter_actor_destroy (priv->video_preview);
2475 priv->video_preview = NULL;
2477 /* If we destroy the preview while it's being dragged, we won't
2478 * get the ::drag-end signal, so manually destroy the clone */
2479 if (priv->drag_preview != NULL)
2481 clutter_actor_destroy (priv->drag_preview);
2482 empathy_call_window_show_preview_rectangles (self, FALSE);
2483 priv->drag_preview = NULL;
2486 priv->funnel = NULL;
2488 create_pipeline (self);
2489 /* Call will be started when user will hit the 'redial' button */
2490 priv->start_call_when_playing = FALSE;
2491 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2497 g_message ("Error: could not destroy pipeline. Closing call window");
2498 gtk_widget_destroy (GTK_WIDGET (self));
2505 reset_details_pane (EmpathyCallWindow *self)
2507 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2509 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2510 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2511 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2512 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2516 empathy_call_window_disconnected (EmpathyCallWindow *self,
2519 gboolean could_disconnect = FALSE;
2520 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2521 gboolean could_reset_pipeline;
2523 /* Leave full screen mode if needed */
2524 gtk_window_unfullscreen (GTK_WINDOW (self));
2526 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2527 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2529 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2531 if (priv->call_state == CONNECTING)
2532 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2534 if (priv->call_state != REDIALING)
2535 priv->call_state = DISCONNECTED;
2537 /* Show the toolbar */
2538 clutter_state_set_state (priv->transitions, "fade-in");
2540 if (could_reset_pipeline)
2542 g_mutex_lock (priv->lock);
2544 g_timer_stop (priv->timer);
2546 if (priv->timer_id != 0)
2547 g_source_remove (priv->timer_id);
2550 g_mutex_unlock (priv->lock);
2553 /* We are about to destroy the window, no need to update it or create
2554 * a video preview */
2557 empathy_call_window_status_message (self, _("Disconnected"));
2559 empathy_call_window_show_hangup_button (self, FALSE);
2561 /* Unsensitive the camera and mic button */
2562 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2563 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2565 /* Be sure that the mic button is enabled */
2566 gtk_toggle_tool_button_set_active (
2567 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2569 if (priv->camera_state == CAMERA_STATE_ON)
2571 /* Restart the preview with the new pipeline. */
2572 display_video_preview (self, TRUE);
2575 /* destroy the video output; it will be recreated when we'll redial */
2576 disconnect_video_output_motion_handler (self);
2577 if (priv->video_output != NULL)
2578 clutter_actor_destroy (priv->video_output);
2579 priv->video_output = NULL;
2580 if (priv->got_video_src > 0)
2582 g_source_remove (priv->got_video_src);
2583 priv->got_video_src = 0;
2586 gtk_widget_show (priv->remote_user_avatar_widget);
2588 reset_details_pane (self);
2590 priv->sending_video = FALSE;
2591 priv->call_started = FALSE;
2593 could_disconnect = TRUE;
2595 /* TODO: display the self avatar of the preview (depends if the "Always
2596 * Show Video Preview" is enabled or not) */
2599 return could_disconnect;
2604 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2607 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2608 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2610 if (empathy_call_window_disconnected (self, TRUE) &&
2611 priv->call_state == REDIALING)
2612 empathy_call_window_restart_call (self);
2616 empathy_call_window_content_is_raw (TfContent *content)
2618 FsConference *conference;
2621 g_object_get (content, "fs-conference", &conference, NULL);
2622 g_assert (conference != NULL);
2624 /* FIXME: Ugly hack, update when moving a packetization property into
2626 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2627 gst_object_unref (conference);
2633 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2635 EmpathyCallWindow *self)
2637 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2638 FsMediaType media_type;
2640 DEBUG ("removing content");
2642 g_object_get (content, "media-type", &media_type, NULL);
2645 * This assumes that there is only one video stream per channel...
2648 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2650 if (priv->funnel != NULL)
2654 output = priv->video_output_sink;
2656 gst_element_set_state (output, GST_STATE_NULL);
2657 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2659 gst_bin_remove (GST_BIN (priv->pipeline), output);
2660 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2661 priv->funnel = NULL;
2664 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2666 if (priv->audio_output != NULL)
2668 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2670 if (priv->audio_output_added)
2671 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2672 priv->audio_output = NULL;
2673 priv->audio_output_added = FALSE;
2678 g_assert_not_reached ();
2685 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2687 EmpathyCallWindow *self)
2689 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2691 DEBUG ("Framerate changed to %u", framerate);
2693 if (priv->video_input != NULL)
2694 empathy_video_src_set_framerate (priv->video_input, framerate);
2698 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2701 EmpathyCallWindow *self)
2703 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2705 DEBUG ("Resolution changed to %ux%u", width, height);
2707 if (priv->video_input != NULL)
2709 empathy_video_src_set_resolution (priv->video_input, width, height);
2713 /* Called with global lock held */
2715 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2717 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2721 if (priv->funnel == NULL)
2723 output = priv->video_output_sink;
2725 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2729 g_warning ("Could not create fsfunnel");
2733 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2735 gst_object_unref (priv->funnel);
2736 priv->funnel = NULL;
2737 g_warning ("Could not add funnel to pipeline");
2741 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2743 g_warning ("Could not add the video output widget to the pipeline");
2747 if (!gst_element_link (priv->funnel, output))
2749 g_warning ("Could not link output sink to funnel");
2750 goto error_output_added;
2753 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2755 g_warning ("Could not start video sink");
2756 goto error_output_added;
2759 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2761 g_warning ("Could not start funnel");
2762 goto error_output_added;
2766 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2769 g_warning ("Could not get request pad from funnel");
2776 gst_element_set_locked_state (priv->funnel, TRUE);
2777 gst_element_set_locked_state (output, TRUE);
2779 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2780 gst_element_set_state (output, GST_STATE_NULL);
2782 gst_bin_remove (GST_BIN (priv->pipeline), output);
2783 gst_element_set_locked_state (output, FALSE);
2787 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2788 priv->funnel = NULL;
2793 /* Called with global lock held */
2795 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2798 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2800 GstPadTemplate *template;
2802 if (!priv->audio_output_added)
2804 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2806 g_warning ("Could not add audio sink to pipeline");
2807 g_object_unref (priv->audio_output);
2808 goto error_add_output;
2811 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2813 g_warning ("Could not start audio sink");
2818 template = gst_element_class_get_pad_template (
2819 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2821 pad = gst_element_request_pad (priv->audio_output,
2822 template, NULL, NULL);
2826 g_warning ("Could not get sink pad from sink");
2833 gst_element_set_locked_state (priv->audio_output, TRUE);
2834 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2835 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2836 priv->audio_output = NULL;
2844 empathy_call_window_update_timer (gpointer user_data)
2846 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2847 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2848 const gchar *status;
2852 time_ = g_timer_elapsed (priv->timer, NULL);
2854 if (priv->call_state == HELD)
2855 status = _("On hold");
2856 else if (!gtk_toggle_tool_button_get_active (
2857 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2860 status = _("Duration");
2862 /* Translators: 'status - minutes:seconds' the caller has been connected */
2863 str = g_strdup_printf (_("%s — %d:%02dm"),
2865 (int) time_ / 60, (int) time_ % 60);
2866 empathy_call_window_status_message (self, str);
2874 EMP_RESPONSE_BALANCE
2878 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2882 switch (response_id)
2884 case GTK_RESPONSE_CLOSE:
2885 gtk_widget_destroy (GTK_WIDGET (info_bar));
2887 case EMP_RESPONSE_BALANCE:
2888 empathy_url_show (GTK_WIDGET (info_bar),
2889 g_object_get_data (G_OBJECT (info_bar), "uri"));
2895 display_error (EmpathyCallWindow *self,
2899 const gchar *details,
2900 const gchar *button_text,
2902 gint button_response)
2904 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2905 GtkWidget *info_bar;
2906 GtkWidget *content_area;
2913 /* Create info bar */
2914 info_bar = gtk_info_bar_new ();
2916 if (button_text != NULL)
2918 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2919 button_text, button_response);
2920 g_object_set_data_full (G_OBJECT (info_bar),
2921 "uri", g_strdup (uri), g_free);
2924 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2925 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
2927 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2929 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2931 /* hbox containing the image and the messages vbox */
2932 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2933 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2936 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2937 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2939 /* vbox containing the main message and the details expander */
2940 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2941 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2944 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2946 label = gtk_label_new (NULL);
2947 gtk_label_set_markup (GTK_LABEL (label), txt);
2948 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2949 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2952 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2955 if (details != NULL)
2957 GtkWidget *expander;
2959 expander = gtk_expander_new (_("Technical Details"));
2961 txt = g_strdup_printf ("<i>%s</i>", details);
2963 label = gtk_label_new (NULL);
2964 gtk_label_set_markup (GTK_LABEL (label), txt);
2965 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2966 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2969 gtk_container_add (GTK_CONTAINER (expander), label);
2970 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2973 g_signal_connect (info_bar, "response",
2974 G_CALLBACK (on_error_infobar_response_cb), NULL);
2976 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2977 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2978 gtk_widget_show_all (info_bar);
2983 media_stream_error_to_txt (EmpathyCallWindow *self,
2984 TpCallChannel *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 TpCallChannel *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 (TpCallChannel *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 (TpCallChannel *call,
3093 EmpathyCallWindow *self)
3095 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3096 "camera-web", _("Can't establish video stream"));
3101 show_balance_error (EmpathyCallWindow *self)
3105 gchar *balance, *tmp;
3106 const gchar *uri, *currency;
3110 g_object_get (self->priv->handler,
3111 "call-channel", &call,
3114 conn = tp_channel_borrow_connection (call);
3115 g_object_unref (call);
3117 uri = tp_connection_get_balance_uri (conn);
3119 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3121 /* unknown balance */
3122 balance = g_strdup ("(--)");
3126 char *money = empathy_format_currency (amount, scale, currency);
3128 balance = g_strdup_printf ("%s %s",
3133 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3135 display_error (self,
3137 _("Sorry, you don’t have enough credit for that call."),
3141 EMP_RESPONSE_BALANCE);
3148 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3151 EmpathyCallWindow *self)
3153 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3154 TpCallChannel *call;
3155 gboolean can_send_video;
3157 if (state == TP_CALL_STATE_ENDED)
3159 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3160 empathy_call_window_disconnected (self, TRUE);
3161 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3162 show_balance_error (self);
3166 if (state != TP_CALL_STATE_ACCEPTED)
3169 if (priv->call_state == CONNECTED)
3172 g_timer_start (priv->timer);
3173 priv->call_state = CONNECTED;
3175 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3177 can_send_video = priv->video_input != NULL &&
3178 empathy_contact_can_voip_video (priv->contact) &&
3179 empathy_camera_monitor_get_available (priv->camera_monitor);
3181 g_object_get (priv->handler, "call-channel", &call, NULL);
3183 if (tp_call_channel_has_dtmf (call))
3184 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3186 if (priv->video_input == NULL)
3187 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3189 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3191 empathy_call_window_show_hangup_button (self, TRUE);
3193 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3195 clutter_actor_hide (priv->video_output);
3196 gtk_widget_show (priv->remote_user_avatar_widget);
3198 g_object_unref (call);
3200 g_mutex_lock (priv->lock);
3202 priv->timer_id = g_timeout_add_seconds (1,
3203 empathy_call_window_update_timer, self);
3205 g_mutex_unlock (priv->lock);
3207 empathy_call_window_update_timer (self);
3209 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3213 empathy_call_window_show_video_output_cb (gpointer user_data)
3215 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3217 if (self->priv->video_output != NULL)
3219 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3220 clutter_actor_show (self->priv->video_output);
3221 empathy_call_window_raise_actors (self);
3228 empathy_call_window_check_video_cb (gpointer data)
3230 EmpathyCallWindow *self = data;
3232 if (self->priv->got_video)
3234 self->priv->got_video = FALSE;
3238 /* No video in the last N seconds, display the remote avatar */
3239 empathy_call_window_show_video_output (self, FALSE);
3244 /* Called from the streaming thread */
3246 empathy_call_window_video_probe_cb (GstPad *pad,
3247 GstMiniObject *mini_obj,
3248 EmpathyCallWindow *self)
3251 if (GST_IS_EVENT (mini_obj))
3254 if (G_UNLIKELY (!self->priv->got_video))
3256 /* show the remote video */
3257 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3258 empathy_call_window_show_video_output_cb,
3259 g_object_ref (self), g_object_unref);
3261 self->priv->got_video = TRUE;
3267 /* Called from the streaming thread */
3269 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3270 TfContent *content, GstPad *src, gpointer user_data)
3272 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3273 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3274 gboolean retval = FALSE;
3279 g_mutex_lock (priv->lock);
3281 g_object_get (content, "media-type", &media_type, NULL);
3285 case TP_MEDIA_STREAM_TYPE_AUDIO:
3286 pad = empathy_call_window_get_audio_sink_pad (self, content);
3288 case TP_MEDIA_STREAM_TYPE_VIDEO:
3289 g_idle_add (empathy_call_window_show_video_output_cb, self);
3290 pad = empathy_call_window_get_video_sink_pad (self);
3292 gst_pad_add_data_probe (src,
3293 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3294 if (priv->got_video_src > 0)
3295 g_source_remove (priv->got_video_src);
3296 priv->got_video_src = g_timeout_add_seconds (1,
3297 empathy_call_window_check_video_cb, self);
3300 g_assert_not_reached ();
3306 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3307 g_warning ("Could not link %s sink pad",
3308 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3312 gst_object_unref (pad);
3316 /* If no sink could be linked, try to add fakesink to prevent the whole call
3321 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3323 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3325 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3326 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3327 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3329 gst_element_set_locked_state (fakesink, TRUE);
3330 gst_element_set_state (fakesink, GST_STATE_NULL);
3331 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3335 DEBUG ("Could not link real sink, linked fakesink instead");
3337 gst_object_unref (sinkpad);
3341 gst_object_unref (fakesink);
3346 g_mutex_unlock (priv->lock);
3352 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3355 EmpathyCallWindowPriv *priv = self->priv;
3357 g_assert (priv->audio_output_added == FALSE);
3358 g_assert (priv->audio_output == FALSE);
3360 priv->audio_output = empathy_audio_sink_new ();
3361 g_object_ref_sink (priv->audio_output);
3363 /* volume button to output volume linking */
3364 g_object_bind_property (priv->audio_output, "volume",
3365 priv->volume_button, "value",
3366 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3368 g_object_bind_property_full (content, "requested-output-volume",
3369 priv->audio_output, "volume",
3371 audio_control_volume_to_element,
3372 element_volume_to_audio_control,
3375 /* Link volumes together, sync the current audio input volume property
3376 * back to farstream first */
3377 g_object_bind_property_full (priv->audio_output, "volume",
3378 content, "reported-output-volume",
3379 G_BINDING_SYNC_CREATE,
3380 element_volume_to_audio_control,
3381 audio_control_volume_to_element,
3384 /* For raw audio conferences assume that the producer of the raw data
3385 * has already processed it, so turn off any echo cancellation and any
3386 * other audio improvements that come with it */
3387 empathy_audio_sink_set_echo_cancel (
3388 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3389 !empathy_call_window_content_is_raw (content));
3394 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3395 TfContent *content, gpointer user_data)
3397 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3398 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3400 FsMediaType media_type;
3401 gboolean retval = FALSE;
3403 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3404 g_assert (sink != NULL);
3408 case FS_MEDIA_TYPE_AUDIO:
3410 /* For raw audio conferences assume that the receiver of the raw data
3411 * wants it unprocessed, so turn off any echo cancellation and any
3412 * other audio improvements that come with it */
3413 empathy_audio_src_set_echo_cancel (
3414 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3415 !empathy_call_window_content_is_raw (content));
3417 /* Link volumes together, sync the current audio input volume property
3418 * back to farstream first */
3419 g_object_bind_property_full (content, "requested-input-volume",
3420 priv->audio_input, "volume",
3422 audio_control_volume_to_element,
3423 element_volume_to_audio_control,
3426 g_object_bind_property_full (priv->audio_input, "volume",
3427 content, "reported-input-volume",
3428 G_BINDING_SYNC_CREATE,
3429 element_volume_to_audio_control,
3430 audio_control_volume_to_element,
3433 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3435 g_warning ("Could not add audio source to pipeline");
3439 pad = gst_element_get_static_pad (priv->audio_input, "src");
3442 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3443 g_warning ("Could not get source pad from audio source");
3447 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3449 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3450 gst_object_unref (pad);
3451 g_warning ("Could not link audio source to farsight");
3454 gst_object_unref (pad);
3456 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3458 g_warning ("Could not start audio source");
3459 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3460 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3464 /* Prepare our audio output, not added yet though */
3465 empathy_call_window_prepare_audio_output (self, content);
3469 case FS_MEDIA_TYPE_VIDEO:
3470 if (priv->video_tee != NULL)
3472 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3473 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3475 g_warning ("Could not link video source input pipeline");
3478 gst_object_unref (pad);
3484 g_assert_not_reached ();
3487 gst_object_unref (sink);
3492 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3494 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3495 GstElement *preview;
3497 disable_camera (self);
3499 DEBUG ("remove video input");
3500 preview = priv->video_preview_sink;
3502 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3503 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3504 gst_element_set_state (preview, GST_STATE_NULL);
3506 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3509 g_object_unref (priv->video_input);
3510 priv->video_input = NULL;
3511 g_object_unref (priv->video_tee);
3512 priv->video_tee = NULL;
3513 clutter_actor_destroy (priv->video_preview);
3514 priv->video_preview = NULL;
3516 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3520 start_call (EmpathyCallWindow *self)
3522 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3524 priv->call_started = TRUE;
3525 empathy_call_handler_start_call (priv->handler,
3526 gtk_get_current_event_time ());
3528 if (empathy_call_handler_has_initial_video (priv->handler))
3530 TpCallChannel *call;
3533 g_object_get (priv->handler, "call-channel", &call, NULL);
3534 /* If the call channel isn't set yet we're requesting it, if we're
3535 * requesting it with initial video it should be PENDING_SEND when we get
3538 s = TP_SENDING_STATE_PENDING_SEND;
3540 s = empathy_call_channel_get_video_state (call);
3542 if (s == TP_SENDING_STATE_PENDING_SEND ||
3543 s == TP_SENDING_STATE_SENDING)
3545 /* Enable 'send video' buttons and display the preview */
3546 gtk_toggle_tool_button_set_active (
3547 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3551 gtk_toggle_tool_button_set_active (
3552 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3554 if (priv->video_preview == NULL)
3556 create_video_preview (self);
3557 add_video_preview_to_pipeline (self);
3562 g_object_unref (call);
3567 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3570 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3571 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3572 GstState newstate, pending;
3574 empathy_call_handler_bus_message (priv->handler, bus, message);
3576 switch (GST_MESSAGE_TYPE (message))
3578 case GST_MESSAGE_STATE_CHANGED:
3579 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3581 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3583 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3584 !priv->call_started)
3586 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3587 if (newstate == GST_STATE_PAUSED)
3589 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3590 priv->pipeline_playing = TRUE;
3592 if (priv->start_call_when_playing)
3596 if (priv->video_preview_sink != NULL &&
3597 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3599 gst_message_parse_state_changed (message, NULL, &newstate,
3602 if (newstate == GST_STATE_PLAYING &&
3603 pending == GST_STATE_VOID_PENDING)
3604 empathy_call_window_stop_camera_spinning (self);
3607 case GST_MESSAGE_ERROR:
3609 GError *error = NULL;
3610 GstElement *gst_error;
3613 gst_message_parse_error (message, &error, &debug);
3614 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3616 g_message ("Element error: %s -- %s\n", error->message, debug);
3618 if (g_str_has_prefix (gst_element_get_name (gst_error),
3619 VIDEO_INPUT_ERROR_PREFIX))
3621 /* Remove the video input and continue */
3622 if (priv->video_input != NULL)
3623 empathy_call_window_remove_video_input (self);
3624 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3628 empathy_call_window_disconnected (self, TRUE);
3630 g_error_free (error);
3633 case GST_MESSAGE_UNKNOWN:
3634 case GST_MESSAGE_EOS:
3635 case GST_MESSAGE_WARNING:
3636 case GST_MESSAGE_INFO:
3637 case GST_MESSAGE_TAG:
3638 case GST_MESSAGE_BUFFERING:
3639 case GST_MESSAGE_STATE_DIRTY:
3640 case GST_MESSAGE_STEP_DONE:
3641 case GST_MESSAGE_CLOCK_PROVIDE:
3642 case GST_MESSAGE_CLOCK_LOST:
3643 case GST_MESSAGE_NEW_CLOCK:
3644 case GST_MESSAGE_STRUCTURE_CHANGE:
3645 case GST_MESSAGE_STREAM_STATUS:
3646 case GST_MESSAGE_APPLICATION:
3647 case GST_MESSAGE_ELEMENT:
3648 case GST_MESSAGE_SEGMENT_START:
3649 case GST_MESSAGE_SEGMENT_DONE:
3650 case GST_MESSAGE_DURATION:
3651 case GST_MESSAGE_ANY:
3660 empathy_call_window_members_changed_cb (TpCallChannel *call,
3661 GHashTable *updates,
3663 TpCallStateReason *reason,
3664 EmpathyCallWindow *self)
3666 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3667 GHashTableIter iter;
3668 gpointer key, value;
3669 gboolean held = FALSE;
3671 g_hash_table_iter_init (&iter, updates);
3672 while (g_hash_table_iter_next (&iter, &key, &value))
3674 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3676 /* This assumes this is a 1-1 call, otherwise one participant
3677 * putting the call on hold wouldn't mean the call is on hold
3685 priv->call_state = HELD;
3686 else if (priv->call_state == HELD)
3687 priv->call_state = CONNECTED;
3691 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3693 EmpathyCallWindow *self)
3695 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3696 TpCallChannel *call;
3698 g_object_get (priv->handler, "call-channel", &call, NULL);
3703 tp_g_signal_connect_object (call, "audio-stream-error",
3704 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3705 tp_g_signal_connect_object (call, "video-stream-error",
3706 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3709 tp_g_signal_connect_object (call, "members-changed",
3710 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3712 g_object_unref (call);
3716 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3718 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3719 TpCallChannel *call;
3721 g_signal_connect (priv->handler, "state-changed",
3722 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3723 g_signal_connect (priv->handler, "conference-added",
3724 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3725 g_signal_connect (priv->handler, "conference-removed",
3726 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3727 g_signal_connect (priv->handler, "closed",
3728 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3729 g_signal_connect (priv->handler, "src-pad-added",
3730 G_CALLBACK (empathy_call_window_src_added_cb), self);
3731 g_signal_connect (priv->handler, "content-added",
3732 G_CALLBACK (empathy_call_window_content_added_cb), self);
3733 g_signal_connect (priv->handler, "content-removed",
3734 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3736 /* We connect to ::call-channel unconditionally since we'll
3737 * get new channels if we hangup and redial or if we reuse the
3739 g_signal_connect (priv->handler, "notify::call-channel",
3740 G_CALLBACK (call_handler_notify_call_cb), self);
3742 g_signal_connect (priv->handler, "framerate-changed",
3743 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3744 g_signal_connect (priv->handler, "resolution-changed",
3745 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3747 g_object_get (priv->handler, "call-channel", &call, NULL);
3750 /* We won't get notify::call-channel for this channel, so
3751 * directly call the callback. */
3752 call_handler_notify_call_cb (priv->handler, NULL, self);
3753 g_object_unref (call);
3758 empathy_call_window_realized_cb (GtkWidget *widget,
3759 EmpathyCallWindow *self)
3763 /* Make the hangup button twice as wide */
3764 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3765 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3767 empathy_call_window_connect_handler (self);
3769 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3773 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3774 EmpathyCallWindow *window)
3776 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3778 if (priv->pipeline != NULL)
3780 if (priv->bus_message_source_id != 0)
3782 g_source_remove (priv->bus_message_source_id);
3783 priv->bus_message_source_id = 0;
3786 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3789 if (priv->call_state == CONNECTING)
3790 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3796 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3799 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3801 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3806 gtk_widget_hide (priv->dtmf_panel);
3807 gtk_widget_hide (menu);
3808 gtk_widget_hide (priv->toolbar);
3812 if (priv->dialpad_was_visible_before_fs)
3813 gtk_widget_show (priv->dtmf_panel);
3815 gtk_widget_show (menu);
3816 gtk_widget_show (priv->toolbar);
3818 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3819 priv->original_height_before_fs);
3824 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3826 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3828 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3829 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3830 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3831 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3833 if (priv->video_output != NULL)
3836 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3837 priv->video_output, TRUE, TRUE,
3838 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3845 empathy_call_window_state_event_cb (GtkWidget *widget,
3846 GdkEventWindowState *event, EmpathyCallWindow *window)
3848 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3850 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3851 gboolean set_fullscreen = event->new_window_state &
3852 GDK_WINDOW_STATE_FULLSCREEN;
3856 gboolean dialpad_was_visible;
3857 GtkAllocation allocation;
3858 gint original_width, original_height;
3860 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3861 original_width = allocation.width;
3862 original_height = allocation.height;
3864 g_object_get (priv->dtmf_panel,
3865 "visible", &dialpad_was_visible,
3868 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3869 priv->original_width_before_fs = original_width;
3870 priv->original_height_before_fs = original_height;
3872 if (priv->video_output_motion_handler_id == 0 &&
3873 priv->video_output != NULL)
3875 priv->video_output_motion_handler_id = g_signal_connect (
3876 G_OBJECT (priv->video_container), "motion-notify-event",
3877 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3883 disconnect_video_output_motion_handler (window);
3886 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3888 show_controls (window, set_fullscreen);
3889 show_borders (window, set_fullscreen);
3890 gtk_action_set_stock_id (priv->menu_fullscreen,
3891 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3892 priv->is_fullscreen = set_fullscreen;
3899 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3902 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3903 int w, h, dialpad_width;
3904 GtkAllocation allocation;
3906 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3907 w = allocation.width;
3908 h = allocation.height;
3910 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3914 gtk_widget_show (priv->dtmf_panel);
3920 gtk_widget_hide (priv->dtmf_panel);
3924 gtk_window_resize (GTK_WINDOW (window), w, h);
3928 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3931 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3932 TpCallChannel *call;
3934 priv->sending_video = (state == CAMERA_STATE_ON);
3936 if (state == CAMERA_STATE_ON)
3938 /* When we start sending video, we want to show the video preview by
3940 display_video_preview (window, TRUE);
3944 display_video_preview (window, FALSE);
3947 if (priv->call_state != CONNECTED)
3950 g_object_get (priv->handler, "call-channel", &call, NULL);
3951 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3952 empathy_call_channel_send_video (call, priv->sending_video);
3953 g_object_unref (call);
3957 empathy_call_window_hangup_cb (gpointer object,
3958 EmpathyCallWindow *self)
3960 /* stopping the call will put it the ENDED state and
3961 * from state_changed_cb we'll reconfigure the window
3963 empathy_call_handler_stop_call (self->priv->handler);
3967 empathy_call_window_restart_call (EmpathyCallWindow *window)
3969 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3971 /* Remove error info bars */
3972 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3973 (GtkCallback) gtk_widget_destroy, NULL);
3975 create_video_output_widget (window);
3976 priv->outgoing = TRUE;
3977 empathy_call_window_set_state_connecting (window);
3979 if (priv->pipeline_playing)
3980 start_call (window);
3982 /* call will be started when the pipeline is ready */
3983 priv->start_call_when_playing = TRUE;
3985 empathy_call_window_setup_avatars (window, priv->handler);
3987 empathy_call_window_show_hangup_button (window, TRUE);
3991 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3992 EmpathyCallWindow *window)
3996 active = gtk_toggle_tool_button_get_active (button);
3998 empathy_call_window_show_dialpad (window, active);
4002 empathy_call_window_fullscreen_cb (gpointer object,
4003 EmpathyCallWindow *window)
4005 empathy_call_window_fullscreen_toggle (window);
4009 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4011 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4013 if (priv->is_fullscreen)
4014 gtk_window_unfullscreen (GTK_WINDOW (window));
4016 gtk_window_fullscreen (GTK_WINDOW (window));
4020 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4021 GdkEventButton *event, EmpathyCallWindow *window)
4023 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4025 empathy_call_window_video_menu_popup (window, event->button);
4033 empathy_call_window_key_press_cb (GtkWidget *video_output,
4034 GdkEventKey *event, EmpathyCallWindow *window)
4036 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4038 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4040 /* Since we are in fullscreen mode, toggling will bring us back to
4042 empathy_call_window_fullscreen_toggle (window);
4050 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4051 GdkEventMotion *event, EmpathyCallWindow *window)
4053 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4055 if (priv->is_fullscreen)
4057 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4059 /* Show the bottom toolbar */
4060 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4067 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4071 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4073 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4075 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4076 button, gtk_get_current_event_time ());
4077 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4081 empathy_call_window_status_message (EmpathyCallWindow *self,
4084 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4088 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4090 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4092 return priv->ui_manager;
4095 EmpathyGstAudioSrc *
4096 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4098 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4100 return (EmpathyGstAudioSrc *) priv->audio_input;
4103 EmpathyGstVideoSrc *
4104 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4106 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4110 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4111 const gchar *device)
4113 EmpathyGstVideoSrc *video;
4116 /* Restart the camera only if it's already running */
4117 running = (self->priv->video_preview != NULL);
4118 video = empathy_call_window_get_video_src (self);
4121 empathy_call_window_play_camera (self, FALSE);
4123 empathy_video_src_change_device (video, device);
4126 empathy_call_window_play_camera (self, TRUE);