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_SPACING 3
77 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
78 #define OVERLAY_MARGIN 6
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 *remote_user_status_toolbar;
165 GtkWidget *status_label;
166 GtkWidget *hangup_button;
167 GtkWidget *audio_call_button;
168 GtkWidget *video_call_button;
169 GtkWidget *mic_button;
170 GtkWidget *volume_button;
171 GtkWidget *camera_button;
172 GtkWidget *dialpad_button;
174 GtkWidget *bottom_toolbar;
175 ClutterActor *floating_toolbar;
177 GtkAction *menu_fullscreen;
178 GtkAction *menu_swap_camera;
180 ClutterState *transitions;
182 /* The main box covering all the stage, contaning remote avatar/video */
183 ClutterActor *video_box;
184 ClutterLayoutManager *video_layout;
186 /* A bin layout manager containing a bin for previews
187 * and the floating toolbar */
188 ClutterActor *overlay_bin;
189 ClutterLayoutManager *overlay_layout;
191 /* Bin layout for the previews */
192 ClutterActor *preview_box;
193 ClutterLayoutManager *preview_layout;
195 /* Coordinates of the preview drag event's start. */
196 PreviewPosition preview_pos;
198 /* We keep a reference on the hbox which contains the main content so we can
199 easilly repack everything when toggling fullscreen */
200 GtkWidget *content_hbox;
202 /* These are used to accept or reject an incoming call when the status
204 GtkWidget *incoming_call_dialog;
205 TpCallChannel *pending_channel;
206 TpChannelDispatchOperation *pending_cdo;
207 TpAddDispatchOperationContext *pending_context;
209 gulong video_output_motion_handler_id;
210 guint bus_message_source_id;
212 GtkWidget *dtmf_panel;
215 GtkWidget *details_vbox;
216 GtkWidget *vcodec_encoding_label;
217 GtkWidget *acodec_encoding_label;
218 GtkWidget *vcodec_decoding_label;
219 GtkWidget *acodec_decoding_label;
221 GtkWidget *audio_remote_candidate_label;
222 GtkWidget *audio_local_candidate_label;
223 GtkWidget *video_remote_candidate_label;
224 GtkWidget *video_local_candidate_label;
225 GtkWidget *video_remote_candidate_info_img;
226 GtkWidget *video_local_candidate_info_img;
227 GtkWidget *audio_remote_candidate_info_img;
228 GtkWidget *audio_local_candidate_info_img;
230 GstElement *video_input;
231 GstElement *video_preview_sink;
232 GstElement *video_output_sink;
233 GstElement *audio_input;
234 GstElement *audio_output;
235 gboolean audio_output_added;
236 GstElement *pipeline;
237 GstElement *video_tee;
247 gboolean call_started;
248 gboolean sending_video;
249 CameraState camera_state;
251 EmpathyCallWindowFullscreen *fullscreen;
252 gboolean is_fullscreen;
257 guint inactivity_src;
259 /* Those fields represent the state of the window before it actually was in
261 gboolean dialpad_was_visible_before_fs;
262 gint original_width_before_fs;
263 gint original_height_before_fs;
265 gint x, y, w, h, dialpad_width;
268 /* TRUE if the call should be started when the pipeline is playing */
269 gboolean start_call_when_playing;
270 /* TRUE if we requested to set the pipeline in the playing state */
271 gboolean pipeline_playing;
273 EmpathySoundManager *sound_mgr;
276 EmpathyMicMenu *mic_menu;
277 EmpathyCameraMenu *camera_menu;
280 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
282 static void empathy_call_window_realized_cb (GtkWidget *widget,
283 EmpathyCallWindow *window);
285 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
286 GdkEvent *event, EmpathyCallWindow *window);
288 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
289 GdkEventWindowState *event, EmpathyCallWindow *window);
291 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
294 static void empathy_call_window_hangup_cb (gpointer object,
295 EmpathyCallWindow *window);
297 static void empathy_call_window_fullscreen_cb (gpointer object,
298 EmpathyCallWindow *window);
300 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
302 static gboolean empathy_call_window_video_button_press_cb (
303 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
305 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
306 GdkEventKey *event, EmpathyCallWindow *window);
308 static gboolean empathy_call_window_video_output_motion_notify (
309 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
311 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
314 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
316 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
317 EmpathyCallWindow *window);
319 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
321 static void empathy_call_window_status_message (EmpathyCallWindow *window,
324 static gboolean empathy_call_window_bus_message (GstBus *bus,
325 GstMessage *message, gpointer user_data);
328 make_background_transparent (GtkClutterActor *actor)
330 GdkRGBA transparent = { 0., 0., 0., 0. };
333 widget = gtk_clutter_actor_get_widget (actor);
334 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
338 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
341 gtk_widget_set_visible (self->priv->hangup_button, show);
342 gtk_widget_set_visible (self->priv->audio_call_button, !show);
343 gtk_widget_set_visible (self->priv->video_call_button, !show);
347 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
348 EmpathyCallWindow *self)
350 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
351 empathy_call_window_restart_call (self);
355 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
356 EmpathyCallWindow *self)
358 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
359 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
360 empathy_call_window_restart_call (self);
364 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
366 EmpathyCallWindow *self)
371 g_object_get (self->priv->handler, "call-channel", &call, NULL);
373 tones[0] = tp_dtmf_event_to_char (event);
375 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
377 g_object_unref (call);
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 clutter_actor_raise_top (self->priv->overlay_bin);
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_sink (priv->video_input);
431 audio_control_volume_to_element (GBinding *binding,
432 const GValue *source_value,
433 GValue *target_value,
436 /* AudioControl volume is 0-255, with -1 for unknown */
439 hv = g_value_get_int (source_value);
444 g_value_set_double (target_value, hv/255.0);
450 element_volume_to_audio_control (GBinding *binding,
451 const GValue *source_value,
452 GValue *target_value,
457 ev = g_value_get_double (source_value);
458 ev = CLAMP (ev, 0.0, 1.0);
460 g_value_set_int (target_value, ev * 255);
465 create_audio_input (EmpathyCallWindow *self)
467 EmpathyCallWindowPriv *priv = GET_PRIV (self);
469 g_assert (priv->audio_input == NULL);
470 priv->audio_input = empathy_audio_src_new ();
471 gst_object_ref_sink (priv->audio_input);
473 g_object_bind_property (priv->mic_button, "active",
474 priv->audio_input, "mute",
475 G_BINDING_BIDIRECTIONAL |
476 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
480 add_video_preview_to_pipeline (EmpathyCallWindow *self)
482 EmpathyCallWindowPriv *priv = GET_PRIV (self);
485 g_assert (priv->video_preview != NULL);
486 g_assert (priv->pipeline != NULL);
487 g_assert (priv->video_input != NULL);
488 g_assert (priv->video_tee != NULL);
490 preview = priv->video_preview_sink;
492 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
494 g_warning ("Could not add video input to pipeline");
498 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
500 g_warning ("Could not add video preview to pipeline");
504 if (!gst_element_link (priv->video_input, priv->video_tee))
506 g_warning ("Could not link video input to video tee");
510 if (!gst_element_link (priv->video_tee, preview))
512 g_warning ("Could not link video tee to video preview");
518 empathy_call_window_disable_camera_cb (GtkAction *action,
519 EmpathyCallWindow *self)
521 clutter_actor_destroy (self->priv->preview_hidden_button);
523 gtk_toggle_tool_button_set_active (
524 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
528 empathy_call_window_minimise_camera_cb (GtkAction *action,
529 EmpathyCallWindow *self)
531 clutter_actor_hide (self->priv->video_preview);
532 clutter_actor_show (self->priv->preview_hidden_button);
536 empathy_call_window_maximise_camera_cb (GtkAction *action,
537 EmpathyCallWindow *self)
539 clutter_actor_show (self->priv->video_preview);
540 clutter_actor_hide (self->priv->preview_hidden_button);
544 empathy_call_window_swap_camera_cb (GtkAction *action,
545 EmpathyCallWindow *self)
547 const GList *cameras, *l;
550 DEBUG ("Swapping the camera");
552 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
553 current_cam = empathy_video_src_dup_device (
554 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
556 for (l = cameras; l != NULL; l = l->next)
558 EmpathyCamera *camera = l->data;
560 if (!tp_strdiff (camera->device, current_cam))
565 next = l->next->data;
567 next = cameras->data;
569 /* EmpathyCameraMenu will update itself and do the actual change
571 g_settings_set_string (self->priv->settings,
572 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
579 g_free (current_cam);
583 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
584 EmpathyCamera *camera,
585 EmpathyCallWindow *self)
587 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
589 gtk_action_set_visible (self->priv->menu_swap_camera,
590 g_list_length ((GList *) cameras) >= 2);
594 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
595 EmpathyCamera *camera,
596 EmpathyCallWindow *self)
598 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
600 gtk_action_set_visible (self->priv->menu_swap_camera,
601 g_list_length ((GList *) cameras) >= 2);
605 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
606 EmpathyCallWindow *self)
610 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
612 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
613 0, gtk_get_current_event_time ());
614 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
618 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
619 EmpathyCallWindow *self)
623 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
624 "/preview-hidden-menu");
625 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
626 0, gtk_get_current_event_time ());
627 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
630 static ClutterActor *
631 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
632 ClutterBinAlignment x,
633 ClutterBinAlignment y)
635 ClutterActor *rectangle;
637 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
638 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
639 PREVIEW_ROUND_FACTOR));
641 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
643 clutter_actor_hide (rectangle);
649 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
653 self->priv->preview_layout = clutter_bin_layout_new (
654 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
655 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
657 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
659 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
661 self->priv->preview_rectangle1 =
662 empathy_call_window_create_preview_rectangle (self,
663 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
664 self->priv->preview_rectangle2 =
665 empathy_call_window_create_preview_rectangle (self,
666 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
667 self->priv->preview_rectangle3 =
668 empathy_call_window_create_preview_rectangle (self,
669 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
670 self->priv->preview_rectangle4 =
671 empathy_call_window_create_preview_rectangle (self,
672 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
676 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
679 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
680 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
681 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
682 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
686 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
691 guint ret_x = 0, ret_y = 0;
694 if (!clutter_actor_has_allocation (self->priv->preview_box))
697 clutter_actor_get_geometry (self->priv->preview_box, &box);
701 case PREVIEW_POS_TOP_LEFT:
702 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
704 case PREVIEW_POS_TOP_RIGHT:
705 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
706 - SELF_VIDEO_SECTION_WIDTH;
707 ret_y = SELF_VIDEO_SECTION_MARGIN;
709 case PREVIEW_POS_BOTTOM_LEFT:
710 ret_x = SELF_VIDEO_SECTION_MARGIN;
711 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
712 - SELF_VIDEO_SECTION_HEIGHT;
714 case PREVIEW_POS_BOTTOM_RIGHT:
715 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
716 - SELF_VIDEO_SECTION_WIDTH;
717 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
718 - SELF_VIDEO_SECTION_HEIGHT;
721 g_warn_if_reached ();
732 static PreviewPosition
733 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
738 PreviewPosition pos = PREVIEW_POS_NONE;
740 if (!clutter_actor_has_allocation (self->priv->preview_box))
743 clutter_actor_get_geometry (self->priv->preview_box, &box);
745 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
746 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
747 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
748 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
750 pos = PREVIEW_POS_TOP_LEFT;
752 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
753 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
754 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
755 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
757 pos = PREVIEW_POS_TOP_RIGHT;
759 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
760 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
761 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
762 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
764 pos = PREVIEW_POS_BOTTOM_LEFT;
766 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
767 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
768 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
769 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
771 pos = PREVIEW_POS_BOTTOM_RIGHT;
777 static ClutterActor *
778 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
781 ClutterActor *rectangle;
785 case PREVIEW_POS_TOP_LEFT:
786 rectangle = self->priv->preview_rectangle1;
788 case PREVIEW_POS_TOP_RIGHT:
789 rectangle = self->priv->preview_rectangle3;
791 case PREVIEW_POS_BOTTOM_LEFT:
792 rectangle = self->priv->preview_rectangle2;
794 case PREVIEW_POS_BOTTOM_RIGHT:
795 rectangle = self->priv->preview_rectangle4;
805 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
808 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
810 DEBUG ("moving the video preview to %d", pos);
812 self->priv->preview_pos = pos;
816 case PREVIEW_POS_TOP_LEFT:
817 clutter_bin_layout_set_alignment (layout,
818 self->priv->video_preview,
819 CLUTTER_BIN_ALIGNMENT_START,
820 CLUTTER_BIN_ALIGNMENT_START);
822 case PREVIEW_POS_TOP_RIGHT:
823 clutter_bin_layout_set_alignment (layout,
824 self->priv->video_preview,
825 CLUTTER_BIN_ALIGNMENT_END,
826 CLUTTER_BIN_ALIGNMENT_START);
828 case PREVIEW_POS_BOTTOM_LEFT:
829 clutter_bin_layout_set_alignment (layout,
830 self->priv->video_preview,
831 CLUTTER_BIN_ALIGNMENT_START,
832 CLUTTER_BIN_ALIGNMENT_END);
834 case PREVIEW_POS_BOTTOM_RIGHT:
835 clutter_bin_layout_set_alignment (layout,
836 self->priv->video_preview,
837 CLUTTER_BIN_ALIGNMENT_END,
838 CLUTTER_BIN_ALIGNMENT_END);
841 g_warn_if_reached ();
844 g_settings_set_enum (self->priv->settings, "camera-position", pos);
848 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
851 ClutterActor *rectangle;
852 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
854 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
856 empathy_rounded_rectangle_set_border_width (
857 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
858 empathy_rounded_rectangle_set_border_color (
859 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
863 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
864 ClutterActor *rectangle)
866 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
868 clutter_color_shade (&white, 0.55, &darker);
870 empathy_rounded_rectangle_set_border_width (
871 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
872 empathy_rounded_rectangle_set_border_color (
873 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
877 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
879 ClutterActor *rectangle;
881 rectangle = empathy_call_window_get_preview_rectangle (self,
882 self->priv->preview_pos);
884 /* We don't want to darken the rectangle where the preview
887 if (self->priv->preview_rectangle1 != rectangle)
888 empathy_call_window_darken_preview_rectangle (self,
889 self->priv->preview_rectangle1);
891 if (self->priv->preview_rectangle2 != rectangle)
892 empathy_call_window_darken_preview_rectangle (self,
893 self->priv->preview_rectangle2);
895 if (self->priv->preview_rectangle3 != rectangle)
896 empathy_call_window_darken_preview_rectangle (self,
897 self->priv->preview_rectangle3);
899 if (self->priv->preview_rectangle4 != rectangle)
900 empathy_call_window_darken_preview_rectangle (self,
901 self->priv->preview_rectangle4);
905 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
909 ClutterModifierType modifiers,
910 EmpathyCallWindow *self)
912 ClutterActor *stage = clutter_actor_get_stage (actor);
915 self->priv->drag_preview = clutter_clone_new (actor);
917 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
918 self->priv->drag_preview);
920 clutter_actor_transform_stage_point (actor, event_x, event_y,
923 clutter_actor_set_position (self->priv->drag_preview,
924 event_x - rel_x, event_y - rel_y);
926 clutter_drag_action_set_drag_handle (action,
927 self->priv->drag_preview);
929 clutter_actor_set_opacity (actor, 0);
930 clutter_actor_hide (self->priv->preview_shown_button);
932 empathy_call_window_show_preview_rectangles (self, TRUE);
933 empathy_call_window_darken_preview_rectangles (self);
937 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
940 clutter_actor_set_opacity (actor, 255);
944 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
948 ClutterModifierType modifiers,
949 EmpathyCallWindow *self)
954 /* Get the position before destroying the drag actor, otherwise the
955 * preview_box allocation won't be valid and we won't be able to
956 * calculate the position. */
957 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
959 empathy_call_window_get_preview_coordinates (self,
960 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
963 /* Move the preview to the destination and destroy it afterwards */
964 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
967 "signal-swapped-after::completed",
968 clutter_actor_destroy, self->priv->drag_preview,
969 "signal-swapped-after::completed",
970 clutter_actor_show, self->priv->preview_shown_button,
972 empathy_call_window_on_animation_completed_cb, actor,
975 self->priv->drag_preview = NULL;
977 if (pos != PREVIEW_POS_NONE)
978 empathy_call_window_move_video_preview (self, pos);
980 empathy_call_window_show_preview_rectangles (self, FALSE);
984 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
988 EmpathyCallWindow *self)
991 gfloat event_x, event_y;
993 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
995 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
997 if (pos != PREVIEW_POS_NONE)
998 empathy_call_window_highlight_preview_rectangle (self, pos);
1000 empathy_call_window_darken_preview_rectangles (self);
1004 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1005 ClutterCrossingEvent *event,
1006 EmpathyCallWindow *self)
1008 ClutterActor *rectangle;
1010 rectangle = empathy_call_window_get_preview_rectangle (self,
1011 self->priv->preview_pos);
1013 empathy_call_window_highlight_preview_rectangle (self,
1014 self->priv->preview_pos);
1016 clutter_actor_show (rectangle);
1022 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1023 ClutterCrossingEvent *event,
1024 EmpathyCallWindow *self)
1026 ClutterActor *rectangle;
1028 rectangle = empathy_call_window_get_preview_rectangle (self,
1029 self->priv->preview_pos);
1031 empathy_call_window_darken_preview_rectangle (self, rectangle);
1033 clutter_actor_hide (rectangle);
1039 create_video_preview (EmpathyCallWindow *self)
1041 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1042 ClutterLayoutManager *layout;
1043 ClutterActor *preview;
1045 ClutterAction *action;
1047 PreviewPosition pos;
1049 g_assert (priv->video_preview == NULL);
1051 pos = g_settings_get_enum (priv->settings, "camera-position");
1053 preview = empathy_rounded_texture_new ();
1054 clutter_actor_set_size (preview,
1055 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1057 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1058 if (priv->video_preview_sink == NULL)
1059 g_error ("Missing cluttersink, check your clutter-gst installation");
1060 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1061 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1063 /* Add a little offset to the video preview */
1064 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1065 CLUTTER_BIN_ALIGNMENT_CENTER);
1066 priv->video_preview = clutter_box_new (layout);
1067 clutter_actor_set_size (priv->video_preview,
1068 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1069 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1071 /* Spinner for when changing the camera device */
1072 priv->preview_spinner_widget = gtk_spinner_new ();
1073 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1075 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1076 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1077 gtk_widget_show (priv->preview_spinner_widget);
1080 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1081 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1082 priv->preview_spinner_widget);
1083 clutter_actor_set_size (priv->preview_spinner_actor,
1084 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1085 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1086 clutter_actor_hide (priv->preview_spinner_actor);
1088 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1090 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1091 priv->preview_spinner_actor);
1093 g_object_set (priv->video_preview_sink,
1098 /* Translators: this is an "Info" label. It should be as short
1100 button = gtk_button_new_with_label (_("i"));
1101 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (button);
1102 clutter_actor_set_size (b, 24, 24);
1103 clutter_actor_set_margin_right (b, 4);
1104 clutter_actor_set_margin_bottom (b, 2);
1105 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1107 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1108 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1110 g_signal_connect (button, "clicked",
1111 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1114 /* Translators: this is an "Info" label. It should be as short
1116 button = gtk_button_new_with_label (_("i"));
1117 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (button);
1118 clutter_actor_set_size (b, 24, 24);
1119 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1121 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1122 priv->preview_hidden_button,
1123 CLUTTER_BIN_ALIGNMENT_START,
1124 CLUTTER_BIN_ALIGNMENT_END);
1126 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1128 clutter_actor_hide (priv->preview_hidden_button);
1130 g_signal_connect (button, "clicked",
1131 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1134 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1135 priv->video_preview,
1136 CLUTTER_BIN_ALIGNMENT_START,
1137 CLUTTER_BIN_ALIGNMENT_END);
1139 empathy_call_window_move_video_preview (self, pos);
1141 action = clutter_drag_action_new ();
1142 g_signal_connect (action, "drag-begin",
1143 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1144 g_signal_connect (action, "drag-end",
1145 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1146 g_signal_connect (action, "drag-motion",
1147 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1149 g_signal_connect (preview, "enter-event",
1150 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1151 g_signal_connect (preview, "leave-event",
1152 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1154 clutter_actor_add_action (preview, action);
1155 clutter_actor_set_reactive (preview, TRUE);
1156 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1160 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1162 clutter_actor_show (self->priv->preview_spinner_actor);
1163 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1167 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1169 clutter_actor_hide (self->priv->preview_spinner_actor);
1170 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1174 empathy_call_window_play_camera (EmpathyCallWindow *self,
1177 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1178 GstElement *preview;
1181 if (priv->video_preview == NULL)
1183 create_video_preview (self);
1184 add_video_preview_to_pipeline (self);
1189 state = GST_STATE_PLAYING;
1193 empathy_call_window_start_camera_spinning (self);
1194 state = GST_STATE_NULL;
1197 preview = priv->video_preview_sink;
1199 gst_element_set_state (preview, state);
1200 gst_element_set_state (priv->video_tee, state);
1201 gst_element_set_state (priv->video_input, state);
1205 display_video_preview (EmpathyCallWindow *self,
1208 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1210 if (priv->video_preview == NULL)
1212 create_video_preview (self);
1213 add_video_preview_to_pipeline (self);
1218 /* Display the video preview */
1219 DEBUG ("Show video preview");
1221 empathy_call_window_play_camera (self, TRUE);
1222 clutter_actor_show (priv->video_preview);
1223 clutter_actor_raise_top (priv->floating_toolbar);
1227 /* Hide the video preview */
1228 DEBUG ("Hide video preview");
1230 if (priv->video_preview != NULL)
1232 clutter_actor_hide (priv->video_preview);
1233 empathy_call_window_play_camera (self, FALSE);
1239 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1241 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1243 empathy_call_window_status_message (window, _("Connecting…"));
1244 priv->call_state = CONNECTING;
1246 /* Show the toolbar */
1247 clutter_state_set_state (priv->transitions, "fade-in");
1250 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1251 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1255 disable_camera (EmpathyCallWindow *self)
1257 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1259 if (priv->camera_state == CAMERA_STATE_OFF)
1262 DEBUG ("Disable camera");
1264 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1266 priv->camera_state = CAMERA_STATE_OFF;
1270 enable_camera (EmpathyCallWindow *self)
1272 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1274 if (priv->camera_state == CAMERA_STATE_ON)
1277 if (priv->video_input == NULL)
1279 DEBUG ("Can't enable camera, no input");
1283 DEBUG ("Enable camera");
1285 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1287 priv->camera_state = CAMERA_STATE_ON;
1291 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1292 EmpathyCallWindow *self)
1294 if (gtk_toggle_tool_button_get_active (toggle))
1295 enable_camera (self);
1297 disable_camera (self);
1301 create_pipeline (EmpathyCallWindow *self)
1303 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1306 g_assert (priv->pipeline == NULL);
1308 priv->pipeline = gst_pipeline_new (NULL);
1309 priv->pipeline_playing = FALSE;
1311 priv->video_tee = gst_element_factory_make ("tee", NULL);
1312 gst_object_ref_sink (priv->video_tee);
1314 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1316 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1317 priv->bus_message_source_id = gst_bus_add_watch (bus,
1318 empathy_call_window_bus_message, self);
1320 g_object_unref (bus);
1324 empathy_call_window_settings_cb (GtkAction *action,
1325 EmpathyCallWindow *self)
1327 gchar *args = g_strdup_printf ("-p %s",
1328 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1330 empathy_launch_program (BIN_DIR, "empathy", args);
1336 empathy_call_window_contents_cb (GtkAction *action,
1337 EmpathyCallWindow *self)
1339 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1343 empathy_call_window_debug_cb (GtkAction *action,
1344 EmpathyCallWindow *self)
1346 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1350 empathy_call_window_about_cb (GtkAction *action,
1351 EmpathyCallWindow *self)
1353 empathy_about_dialog_new (GTK_WINDOW (self));
1357 empathy_call_window_toolbar_timeout (gpointer data)
1359 EmpathyCallWindow *self = data;
1361 /* We don't want to hide the toolbar if we're not in a call, as
1362 * to show the call status all the time. */
1363 if (self->priv->call_state != CONNECTING &&
1364 self->priv->call_state != DISCONNECTED)
1365 clutter_state_set_state (self->priv->transitions, "fade-out");
1371 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1373 EmpathyCallWindow *self)
1375 clutter_state_set_state (self->priv->transitions, "fade-in");
1377 if (self->priv->inactivity_src > 0)
1378 g_source_remove (self->priv->inactivity_src);
1380 self->priv->inactivity_src = g_timeout_add_seconds (3,
1381 empathy_call_window_toolbar_timeout, self);
1387 empathy_call_window_configure_event_cb (GtkWidget *widget,
1389 EmpathyCallWindow *self)
1391 GdkWindow *gdk_window;
1392 GdkWindowState window_state;
1394 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1395 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1397 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1398 &self->priv->dialpad_width, NULL);
1400 gdk_window = gtk_widget_get_window (widget);
1401 window_state = gdk_window_get_state (gdk_window);
1402 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1408 empathy_call_window_destroyed_cb (GtkWidget *object,
1409 EmpathyCallWindow *self)
1411 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1413 /* Save the geometry as if the dialpad was hidden. */
1414 empathy_geometry_save_values (GTK_WINDOW (self),
1415 self->priv->x, self->priv->y,
1416 self->priv->w - self->priv->dialpad_width, self->priv->h,
1417 self->priv->maximized);
1422 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1424 EmpathyCallWindow *self)
1426 switch (response_id)
1428 case GTK_RESPONSE_ACCEPT:
1429 tp_channel_dispatch_operation_handle_with_async (
1430 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1432 tp_clear_object (&self->priv->pending_cdo);
1433 tp_clear_object (&self->priv->pending_channel);
1434 tp_clear_object (&self->priv->pending_context);
1437 case GTK_RESPONSE_CANCEL:
1438 tp_channel_dispatch_operation_close_channels_async (
1439 self->priv->pending_cdo, NULL, NULL);
1441 empathy_call_window_status_message (self, _("Disconnected"));
1442 self->priv->call_state = DISCONNECTED;
1445 g_warn_if_reached ();
1450 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1454 g_assert (self->priv->call_state != CONNECTED);
1456 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1458 empathy_call_window_status_message (self, _("Incoming call"));
1459 self->priv->call_state = RINGING;
1461 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1462 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1463 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1464 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1465 empathy_contact_get_alias (self->priv->contact));
1467 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1468 _("Reject"), GTK_RESPONSE_CANCEL,
1469 _("Answer"), GTK_RESPONSE_ACCEPT,
1472 g_signal_connect (self->priv->incoming_call_dialog, "response",
1473 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1474 gtk_widget_show (self->priv->incoming_call_dialog);
1478 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1482 EmpathyCallWindow *self)
1484 tp_clear_object (&self->priv->pending_cdo);
1485 tp_clear_object (&self->priv->pending_channel);
1486 tp_clear_object (&self->priv->pending_context);
1488 /* We don't know if the incoming call has been accepted or not, so we
1489 * assume it hasn't and if it has, we'll set the proper status when
1490 * we get the new handler. */
1491 empathy_call_window_status_message (self, _("Disconnected"));
1492 self->priv->call_state = DISCONNECTED;
1494 gtk_widget_destroy (self->priv->incoming_call_dialog);
1495 self->priv->incoming_call_dialog = NULL;
1499 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1500 TpCallChannel *channel,
1501 TpChannelDispatchOperation *dispatch_operation,
1502 TpAddDispatchOperationContext *context)
1504 g_assert (self->priv->pending_channel == NULL);
1505 g_assert (self->priv->pending_context == NULL);
1506 g_assert (self->priv->pending_cdo == NULL);
1508 /* Start ringing and delay until the user answers or hangs. */
1509 self->priv->pending_channel = g_object_ref (channel);
1510 self->priv->pending_context = g_object_ref (context);
1511 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1513 g_signal_connect (self->priv->pending_cdo, "invalidated",
1514 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1516 empathy_call_window_set_state_ringing (self);
1517 tp_add_dispatch_operation_context_accept (context);
1521 empathy_call_window_init (EmpathyCallWindow *self)
1523 EmpathyCallWindowPriv *priv;
1525 GtkWidget *top_vbox;
1527 ClutterConstraint *constraint;
1528 ClutterActor *remote_avatar;
1529 GtkCssProvider *provider;
1530 ClutterColor black = { 0, 0, 0, 0 };
1531 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1532 OVERLAY_MARGIN, OVERLAY_MARGIN };
1534 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1535 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1537 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1539 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1540 gui = empathy_builder_get_file (filename,
1541 "call_window_vbox", &top_vbox,
1542 "errors_vbox", &priv->errors_vbox,
1543 "pane", &priv->pane,
1544 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1545 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1546 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1547 "status_label", &priv->status_label,
1548 "audiocall", &priv->audio_call_button,
1549 "videocall", &priv->video_call_button,
1550 "microphone", &priv->mic_button,
1551 "volume", &priv->volume_button,
1552 "camera", &priv->camera_button,
1553 "hangup", &priv->hangup_button,
1554 "dialpad", &priv->dialpad_button,
1555 "toolbar", &priv->toolbar,
1556 "bottom_toolbar", &priv->bottom_toolbar,
1557 "ui_manager", &priv->ui_manager,
1558 "menufullscreen", &priv->menu_fullscreen,
1559 "menupreviewswap", &priv->menu_swap_camera,
1560 "details_vbox", &priv->details_vbox,
1561 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1562 "acodec_encoding_label", &priv->acodec_encoding_label,
1563 "acodec_decoding_label", &priv->acodec_decoding_label,
1564 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1565 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1566 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1567 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1568 "video_local_candidate_label", &priv->video_local_candidate_label,
1569 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1570 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1571 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1572 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1576 empathy_builder_connect (gui, self,
1577 "hangup", "clicked", empathy_call_window_hangup_cb,
1578 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1579 "videocall", "clicked", empathy_call_window_video_call_cb,
1580 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1581 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1582 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1583 "menusettings", "activate", empathy_call_window_settings_cb,
1584 "menucontents", "activate", empathy_call_window_contents_cb,
1585 "menudebug", "activate", empathy_call_window_debug_cb,
1586 "menuabout", "activate", empathy_call_window_about_cb,
1587 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1588 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1589 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1590 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1593 /* FIXME: we should use a stock "OSD" style class for the toolbar,
1594 * once it's available in GTK+/Adwaita.
1596 provider = gtk_css_provider_new ();
1597 gtk_css_provider_load_from_data (provider,
1598 "#CallFloatingToolbar { border-radius: 6px; }", -1, NULL);
1599 gtk_style_context_add_provider (
1600 gtk_widget_get_style_context (priv->bottom_toolbar),
1601 GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1602 g_object_unref (provider);
1604 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1606 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1608 g_object_bind_property (priv->camera_monitor, "available",
1609 priv->camera_button, "sensitive",
1610 G_BINDING_SYNC_CREATE);
1612 g_signal_connect (priv->camera_monitor, "added",
1613 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1614 g_signal_connect (priv->camera_monitor, "removed",
1615 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1617 priv->lock = g_mutex_new ();
1619 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1621 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1622 CONTENT_HBOX_SPACING);
1623 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1626 /* main contents remote avatar/video box */
1627 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1628 CLUTTER_BIN_ALIGNMENT_FILL);
1630 priv->video_box = clutter_box_new (priv->video_layout);
1632 priv->video_container = gtk_clutter_embed_new ();
1634 gtk_widget_set_size_request (priv->video_container,
1635 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1637 /* Set the background black */
1638 clutter_stage_set_color (
1639 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1640 GTK_CLUTTER_EMBED (priv->video_container))),
1643 clutter_container_add (
1644 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1645 GTK_CLUTTER_EMBED (priv->video_container))),
1649 constraint = clutter_bind_constraint_new (
1650 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1651 CLUTTER_BIND_SIZE, 0);
1652 clutter_actor_add_constraint (priv->video_box, constraint);
1654 priv->remote_user_avatar_widget = gtk_image_new ();
1655 remote_avatar = gtk_clutter_actor_new_with_contents (
1656 priv->remote_user_avatar_widget);
1657 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1659 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1662 /* create the overlay bin */
1663 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1664 CLUTTER_BIN_ALIGNMENT_CENTER);
1665 priv->overlay_bin = clutter_actor_new ();
1666 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1668 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1670 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1672 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1674 empathy_call_window_create_preview_rectangles (self);
1676 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1677 priv->video_container, TRUE, TRUE,
1678 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1680 create_pipeline (self);
1681 create_video_output_widget (self);
1682 create_audio_input (self);
1683 create_video_input (self);
1685 priv->floating_toolbar = gtk_clutter_actor_new ();
1686 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1687 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1689 gtk_widget_reparent (priv->bottom_toolbar,
1690 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1692 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1693 priv->floating_toolbar,
1694 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1696 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1698 clutter_actor_raise_top (priv->floating_toolbar);
1700 /* Transitions for the floating toolbar */
1701 priv->transitions = clutter_state_new ();
1703 /* all transitions last for 2s */
1704 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1706 /* transition from any state to "fade-out" state */
1707 clutter_state_set (priv->transitions, NULL, "fade-out",
1708 priv->floating_toolbar,
1709 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1712 /* transition from any state to "fade-in" state */
1713 clutter_state_set (priv->transitions, NULL, "fade-in",
1714 priv->floating_toolbar,
1715 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1718 /* put the actor into the "fade-in" state with no animation */
1719 clutter_state_warp_to_state (priv->transitions, "fade-in");
1721 /* The call will be started as soon the pipeline is playing */
1722 priv->start_call_when_playing = TRUE;
1724 priv->dtmf_panel = empathy_dialpad_widget_new ();
1725 g_signal_connect (priv->dtmf_panel, "start-tone",
1726 G_CALLBACK (dtmf_start_tone_cb), self);
1728 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1731 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1734 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1736 gtk_widget_show_all (top_vbox);
1738 gtk_widget_hide (priv->dtmf_panel);
1739 gtk_widget_hide (priv->details_vbox);
1741 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1743 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1744 priv->video_container);
1746 /* We hide the bottom toolbar after 3s of inactivity and show it
1747 * again on mouse movement */
1748 priv->inactivity_src = g_timeout_add_seconds (3,
1749 empathy_call_window_toolbar_timeout, self);
1751 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1752 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1754 g_signal_connect (G_OBJECT (self), "realize",
1755 G_CALLBACK (empathy_call_window_realized_cb), self);
1757 g_signal_connect (G_OBJECT (self), "delete-event",
1758 G_CALLBACK (empathy_call_window_delete_cb), self);
1760 g_signal_connect (G_OBJECT (self), "window-state-event",
1761 G_CALLBACK (empathy_call_window_state_event_cb), self);
1763 g_signal_connect (G_OBJECT (self), "key-press-event",
1764 G_CALLBACK (empathy_call_window_key_press_cb), self);
1766 g_signal_connect (self, "motion-notify-event",
1767 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1769 priv->timer = g_timer_new ();
1771 g_object_ref (priv->ui_manager);
1772 g_object_unref (gui);
1774 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1775 priv->mic_menu = empathy_mic_menu_new (self);
1776 priv->camera_menu = empathy_camera_menu_new (self);
1778 empathy_call_window_show_hangup_button (self, TRUE);
1780 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1781 /* These signals are used to track the window position and save it
1782 * when the window is destroyed. We need to do this as we don't want
1783 * the window geometry to be saved with the dialpad taken into account. */
1784 g_signal_connect (self, "destroy",
1785 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1786 g_signal_connect (self, "configure-event",
1787 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1788 g_signal_connect (self, "window-state-event",
1789 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1791 /* Don't display labels in both toolbars */
1792 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1795 /* Instead of specifying a width and a height, we specify only one size. That's
1796 because we want a square avatar icon. */
1798 init_contact_avatar_with_size (EmpathyContact *contact,
1799 GtkWidget *image_widget,
1802 GdkPixbuf *pixbuf_avatar = NULL;
1804 if (contact != NULL)
1806 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1810 if (pixbuf_avatar == NULL)
1812 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1813 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1816 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1818 if (pixbuf_avatar != NULL)
1819 g_object_unref (pixbuf_avatar);
1823 set_window_title (EmpathyCallWindow *self)
1825 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1828 if (priv->contact != NULL)
1830 /* translators: Call is a noun and %s is the contact name. This string
1831 * is used in the window title */
1832 tmp = g_strdup_printf (_("Call with %s"),
1833 empathy_contact_get_alias (priv->contact));
1834 gtk_window_set_title (GTK_WINDOW (self), tmp);
1839 g_warning ("Unknown remote contact!");
1844 set_remote_user_name (EmpathyCallWindow *self,
1845 EmpathyContact *contact)
1847 const gchar *alias = empathy_contact_get_alias (contact);
1848 const gchar *status = empathy_contact_get_status (contact);
1850 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1852 if (status != NULL) {
1855 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1856 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1860 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1866 contact_name_changed_cb (EmpathyContact *contact,
1868 EmpathyCallWindow *self)
1870 set_window_title (self);
1871 set_remote_user_name (self, contact);
1875 contact_presence_changed_cb (EmpathyContact *contact,
1877 EmpathyCallWindow *self)
1879 set_remote_user_name (self, contact);
1883 contact_avatar_changed_cb (EmpathyContact *contact,
1885 EmpathyCallWindow *self)
1888 GtkAllocation allocation;
1889 GtkWidget *avatar_widget;
1891 avatar_widget = self->priv->remote_user_avatar_widget;
1893 gtk_widget_get_allocation (avatar_widget, &allocation);
1894 size = allocation.height;
1898 /* the widget is not allocated yet, set a default size */
1899 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1900 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1903 init_contact_avatar_with_size (contact, avatar_widget, size);
1905 avatar_widget = self->priv->remote_user_avatar_toolbar;
1907 gtk_widget_get_allocation (avatar_widget, &allocation);
1908 size = allocation.height;
1912 /* the widget is not allocated yet, set a default size */
1913 size = SMALL_TOOLBAR_SIZE;
1916 init_contact_avatar_with_size (contact, avatar_widget, size);
1920 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1921 EmpathyCallHandler *handler)
1923 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1925 tp_g_signal_connect_object (priv->contact, "notify::name",
1926 G_CALLBACK (contact_name_changed_cb), self, 0);
1927 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1928 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1929 tp_g_signal_connect_object (priv->contact, "notify::presence",
1930 G_CALLBACK (contact_presence_changed_cb), self, 0);
1932 set_window_title (self);
1933 set_remote_user_name (self, priv->contact);
1935 init_contact_avatar_with_size (priv->contact,
1936 priv->remote_user_avatar_widget,
1937 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1938 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1940 init_contact_avatar_with_size (priv->contact,
1941 priv->remote_user_avatar_toolbar,
1942 SMALL_TOOLBAR_SIZE);
1944 /* The remote avatar is shown by default and will be hidden when we receive
1945 video from the remote side. */
1946 clutter_actor_hide (priv->video_output);
1947 gtk_widget_show (priv->remote_user_avatar_widget);
1951 update_send_codec (EmpathyCallWindow *self,
1954 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1961 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1962 widget = priv->acodec_encoding_label;
1966 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1967 widget = priv->vcodec_encoding_label;
1973 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1974 gtk_label_set_text (GTK_LABEL (widget), tmp);
1979 send_audio_codec_notify_cb (GObject *object,
1983 EmpathyCallWindow *self = user_data;
1985 update_send_codec (self, TRUE);
1989 send_video_codec_notify_cb (GObject *object,
1993 EmpathyCallWindow *self = user_data;
1995 update_send_codec (self, FALSE);
1999 update_recv_codec (EmpathyCallWindow *self,
2002 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2005 GString *str = NULL;
2009 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2010 widget = priv->acodec_decoding_label;
2014 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2015 widget = priv->vcodec_decoding_label;
2021 for (l = codecs; l != NULL; l = g_list_next (l))
2023 FsCodec *codec = l->data;
2026 str = g_string_new (NULL);
2028 g_string_append (str, ", ");
2030 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2034 gtk_label_set_text (GTK_LABEL (widget), str->str);
2035 g_string_free (str, TRUE);
2039 recv_audio_codecs_notify_cb (GObject *object,
2043 EmpathyCallWindow *self = user_data;
2045 update_recv_codec (self, TRUE);
2049 recv_video_codecs_notify_cb (GObject *object,
2053 EmpathyCallWindow *self = user_data;
2055 update_recv_codec (self, FALSE);
2058 static const gchar *
2059 candidate_type_to_str (FsCandidate *candidate)
2061 switch (candidate->type)
2063 case FS_CANDIDATE_TYPE_HOST:
2065 case FS_CANDIDATE_TYPE_SRFLX:
2066 return "server reflexive";
2067 case FS_CANDIDATE_TYPE_PRFLX:
2068 return "peer reflexive";
2069 case FS_CANDIDATE_TYPE_RELAY:
2071 case FS_CANDIDATE_TYPE_MULTICAST:
2078 static const gchar *
2079 candidate_type_to_desc (FsCandidate *candidate)
2081 switch (candidate->type)
2083 case FS_CANDIDATE_TYPE_HOST:
2084 return _("The IP address as seen by the machine");
2085 case FS_CANDIDATE_TYPE_SRFLX:
2086 return _("The IP address as seen by a server on the Internet");
2087 case FS_CANDIDATE_TYPE_PRFLX:
2088 return _("The IP address of the peer as seen by the other side");
2089 case FS_CANDIDATE_TYPE_RELAY:
2090 return _("The IP address of a relay server");
2091 case FS_CANDIDATE_TYPE_MULTICAST:
2092 return _("The IP address of the multicast group");
2099 update_candidat_widget (EmpathyCallWindow *self,
2102 FsCandidate *candidate)
2106 g_assert (candidate != NULL);
2107 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2108 candidate->port, candidate_type_to_str (candidate));
2110 gtk_label_set_text (GTK_LABEL (label), str);
2111 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2117 candidates_changed_cb (GObject *object,
2119 EmpathyCallWindow *self)
2121 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2122 FsCandidate *candidate = NULL;
2124 if (type == FS_MEDIA_TYPE_VIDEO)
2126 /* Update remote candidate */
2127 candidate = empathy_call_handler_get_video_remote_candidate (
2130 update_candidat_widget (self, priv->video_remote_candidate_label,
2131 priv->video_remote_candidate_info_img, candidate);
2133 /* Update local candidate */
2134 candidate = empathy_call_handler_get_video_local_candidate (
2137 update_candidat_widget (self, priv->video_local_candidate_label,
2138 priv->video_local_candidate_info_img, candidate);
2142 /* Update remote candidate */
2143 candidate = empathy_call_handler_get_audio_remote_candidate (
2146 update_candidat_widget (self, priv->audio_remote_candidate_label,
2147 priv->audio_remote_candidate_info_img, candidate);
2149 /* Update local candidate */
2150 candidate = empathy_call_handler_get_audio_local_candidate (
2153 update_candidat_widget (self, priv->audio_local_candidate_label,
2154 priv->audio_local_candidate_info_img, candidate);
2159 empathy_call_window_constructed (GObject *object)
2161 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2162 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2163 TpCallChannel *call;
2166 g_assert (priv->handler != NULL);
2168 g_object_get (priv->handler, "call-channel", &call, NULL);
2169 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2170 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2171 tp_clear_object (&call);
2173 priv->contact = empathy_call_handler_get_contact (priv->handler);
2174 g_assert (priv->contact != NULL);
2175 g_object_ref (priv->contact);
2177 if (!empathy_contact_can_voip_video (priv->contact))
2179 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2180 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2183 empathy_call_window_setup_avatars (self, priv->handler);
2184 empathy_call_window_set_state_connecting (self);
2186 if (!empathy_call_handler_has_initial_video (priv->handler))
2188 gtk_toggle_tool_button_set_active (
2189 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2191 /* If call has InitialVideo, the preview will be started once the call has
2192 * been started (start_call()). */
2194 update_send_codec (self, TRUE);
2195 update_send_codec (self, FALSE);
2196 update_recv_codec (self, TRUE);
2197 update_recv_codec (self, FALSE);
2199 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2200 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2201 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2202 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2203 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2204 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2205 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2206 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2208 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2209 G_CALLBACK (candidates_changed_cb), self, 0);
2212 static void empathy_call_window_dispose (GObject *object);
2213 static void empathy_call_window_finalize (GObject *object);
2216 empathy_call_window_set_property (GObject *object,
2217 guint property_id, const GValue *value, GParamSpec *pspec)
2219 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2221 switch (property_id)
2223 case PROP_CALL_HANDLER:
2224 priv->handler = g_value_dup_object (value);
2227 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2232 empathy_call_window_get_property (GObject *object,
2233 guint property_id, GValue *value, GParamSpec *pspec)
2235 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2237 switch (property_id)
2239 case PROP_CALL_HANDLER:
2240 g_value_set_object (value, priv->handler);
2243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2248 empathy_call_window_class_init (
2249 EmpathyCallWindowClass *empathy_call_window_class)
2251 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2252 GParamSpec *param_spec;
2254 g_type_class_add_private (empathy_call_window_class,
2255 sizeof (EmpathyCallWindowPriv));
2257 object_class->constructed = empathy_call_window_constructed;
2258 object_class->set_property = empathy_call_window_set_property;
2259 object_class->get_property = empathy_call_window_get_property;
2261 object_class->dispose = empathy_call_window_dispose;
2262 object_class->finalize = empathy_call_window_finalize;
2264 param_spec = g_param_spec_object ("handler",
2265 "handler", "The call handler",
2266 EMPATHY_TYPE_CALL_HANDLER,
2267 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2268 g_object_class_install_property (object_class,
2269 PROP_CALL_HANDLER, param_spec);
2273 empathy_call_window_dispose (GObject *object)
2275 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2276 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2278 if (priv->dispose_has_run)
2281 priv->dispose_has_run = TRUE;
2283 if (priv->handler != NULL)
2285 empathy_call_handler_stop_call (priv->handler);
2286 tp_clear_object (&priv->handler);
2289 if (priv->bus_message_source_id != 0)
2291 g_source_remove (priv->bus_message_source_id);
2292 priv->bus_message_source_id = 0;
2295 if (priv->got_video_src > 0)
2297 g_source_remove (priv->got_video_src);
2298 priv->got_video_src = 0;
2301 if (priv->inactivity_src > 0)
2303 g_source_remove (priv->inactivity_src);
2304 priv->inactivity_src = 0;
2307 tp_clear_object (&priv->pipeline);
2308 tp_clear_object (&priv->video_input);
2309 tp_clear_object (&priv->audio_input);
2310 tp_clear_object (&priv->video_tee);
2311 tp_clear_object (&priv->ui_manager);
2312 tp_clear_object (&priv->fullscreen);
2313 tp_clear_object (&priv->camera_monitor);
2314 tp_clear_object (&priv->settings);
2315 tp_clear_object (&priv->sound_mgr);
2316 tp_clear_object (&priv->mic_menu);
2317 tp_clear_object (&priv->camera_menu);
2318 tp_clear_object (&priv->transitions);
2320 g_list_free_full (priv->notifiers, g_object_unref);
2322 if (priv->timer_id != 0)
2323 g_source_remove (priv->timer_id);
2326 tp_clear_object (&priv->contact);
2328 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2332 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2334 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2336 if (priv->video_output_motion_handler_id != 0)
2338 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2339 priv->video_output_motion_handler_id);
2340 priv->video_output_motion_handler_id = 0;
2345 empathy_call_window_finalize (GObject *object)
2347 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2348 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2350 disconnect_video_output_motion_handler (self);
2352 /* free any data held directly by the object here */
2353 g_mutex_free (priv->lock);
2355 g_timer_destroy (priv->timer);
2357 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2362 empathy_call_window_new (EmpathyCallHandler *handler)
2364 return EMPATHY_CALL_WINDOW (
2365 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2369 empathy_call_window_present (EmpathyCallWindow *self,
2370 EmpathyCallHandler *handler)
2372 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2374 empathy_window_present (GTK_WINDOW (self));
2376 if (self->priv->call_state == DISCONNECTED)
2378 /* start a new call if one is not already in progress */
2379 tp_clear_object (&self->priv->handler);
2380 self->priv->handler = g_object_ref (handler);
2381 empathy_call_window_connect_handler (self);
2383 empathy_call_window_restart_call (self);
2388 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2389 GstElement *conference, gpointer user_data)
2391 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2392 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2393 FsElementAddedNotifier *notifier;
2396 DEBUG ("Conference added");
2398 /* Add notifier to set the various element properties as needed */
2399 notifier = fs_element_added_notifier_new ();
2400 keyfile = fs_utils_get_default_element_properties (conference);
2402 if (keyfile != NULL)
2403 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2405 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2407 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2409 gst_bin_add (GST_BIN (priv->pipeline), conference);
2410 gst_element_set_state (conference, GST_STATE_PLAYING);
2414 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2415 GstElement *conference, gpointer user_data)
2417 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2418 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2420 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2421 gst_element_set_state (conference, GST_STATE_NULL);
2425 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2427 GstStateChangeReturn state_change_return;
2428 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2430 if (priv->pipeline == NULL)
2433 if (priv->bus_message_source_id != 0)
2435 g_source_remove (priv->bus_message_source_id);
2436 priv->bus_message_source_id = 0;
2439 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2441 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2442 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2444 if (priv->pipeline != NULL)
2445 g_object_unref (priv->pipeline);
2446 priv->pipeline = NULL;
2448 if (priv->audio_output != NULL)
2449 g_object_unref (priv->audio_output);
2450 priv->audio_output = NULL;
2451 priv->audio_output_added = FALSE;
2453 if (priv->video_tee != NULL)
2454 g_object_unref (priv->video_tee);
2455 priv->video_tee = NULL;
2457 if (priv->video_preview != NULL)
2458 clutter_actor_destroy (priv->video_preview);
2459 priv->video_preview = NULL;
2461 /* If we destroy the preview while it's being dragged, we won't
2462 * get the ::drag-end signal, so manually destroy the clone */
2463 if (priv->drag_preview != NULL)
2465 clutter_actor_destroy (priv->drag_preview);
2466 empathy_call_window_show_preview_rectangles (self, FALSE);
2467 priv->drag_preview = NULL;
2470 priv->funnel = NULL;
2472 create_pipeline (self);
2473 /* Call will be started when user will hit the 'redial' button */
2474 priv->start_call_when_playing = FALSE;
2475 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2481 g_message ("Error: could not destroy pipeline. Closing call window");
2482 gtk_widget_destroy (GTK_WIDGET (self));
2489 reset_details_pane (EmpathyCallWindow *self)
2491 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2493 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2494 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2495 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2496 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2500 empathy_call_window_disconnected (EmpathyCallWindow *self,
2503 gboolean could_disconnect = FALSE;
2504 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2505 gboolean could_reset_pipeline;
2507 /* Leave full screen mode if needed */
2508 gtk_window_unfullscreen (GTK_WINDOW (self));
2510 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2511 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2513 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2515 if (priv->call_state == CONNECTING)
2516 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2518 if (priv->call_state != REDIALING)
2519 priv->call_state = DISCONNECTED;
2521 /* Show the toolbar */
2522 clutter_state_set_state (priv->transitions, "fade-in");
2524 if (could_reset_pipeline)
2526 g_mutex_lock (priv->lock);
2528 g_timer_stop (priv->timer);
2530 if (priv->timer_id != 0)
2531 g_source_remove (priv->timer_id);
2534 g_mutex_unlock (priv->lock);
2537 /* We are about to destroy the window, no need to update it or create
2538 * a video preview */
2541 empathy_call_window_status_message (self, _("Disconnected"));
2543 empathy_call_window_show_hangup_button (self, FALSE);
2545 /* Unsensitive the camera and mic button */
2546 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2547 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2549 /* Be sure that the mic button is enabled */
2550 gtk_toggle_tool_button_set_active (
2551 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2553 if (priv->camera_state == CAMERA_STATE_ON)
2555 /* Restart the preview with the new pipeline. */
2556 display_video_preview (self, TRUE);
2559 /* destroy the video output; it will be recreated when we'll redial */
2560 disconnect_video_output_motion_handler (self);
2561 if (priv->video_output != NULL)
2562 clutter_actor_destroy (priv->video_output);
2563 priv->video_output = NULL;
2564 if (priv->got_video_src > 0)
2566 g_source_remove (priv->got_video_src);
2567 priv->got_video_src = 0;
2570 gtk_widget_show (priv->remote_user_avatar_widget);
2572 reset_details_pane (self);
2574 priv->sending_video = FALSE;
2575 priv->call_started = FALSE;
2577 could_disconnect = TRUE;
2579 /* TODO: display the self avatar of the preview (depends if the "Always
2580 * Show Video Preview" is enabled or not) */
2583 return could_disconnect;
2588 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2591 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2592 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2594 if (empathy_call_window_disconnected (self, TRUE) &&
2595 priv->call_state == REDIALING)
2596 empathy_call_window_restart_call (self);
2600 empathy_call_window_content_is_raw (TfContent *content)
2602 FsConference *conference;
2605 g_object_get (content, "fs-conference", &conference, NULL);
2606 g_assert (conference != NULL);
2608 /* FIXME: Ugly hack, update when moving a packetization property into
2610 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2611 gst_object_unref (conference);
2617 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2619 EmpathyCallWindow *self)
2621 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2622 FsMediaType media_type;
2624 DEBUG ("removing content");
2626 g_object_get (content, "media-type", &media_type, NULL);
2629 * This assumes that there is only one video stream per channel...
2632 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2634 if (priv->funnel != NULL)
2638 output = priv->video_output_sink;
2640 gst_element_set_state (output, GST_STATE_NULL);
2641 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2643 gst_bin_remove (GST_BIN (priv->pipeline), output);
2644 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2645 priv->funnel = NULL;
2648 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2650 if (priv->audio_output != NULL)
2652 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2654 if (priv->audio_output_added)
2655 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2656 priv->audio_output = NULL;
2657 priv->audio_output_added = FALSE;
2662 g_assert_not_reached ();
2669 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2671 EmpathyCallWindow *self)
2673 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2675 DEBUG ("Framerate changed to %u", framerate);
2677 if (priv->video_input != NULL)
2678 empathy_video_src_set_framerate (priv->video_input, framerate);
2682 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2685 EmpathyCallWindow *self)
2687 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2689 DEBUG ("Resolution changed to %ux%u", width, height);
2691 if (priv->video_input != NULL)
2693 empathy_video_src_set_resolution (priv->video_input, width, height);
2697 /* Called with global lock held */
2699 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2701 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2705 if (priv->funnel == NULL)
2707 output = priv->video_output_sink;
2709 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2713 g_warning ("Could not create fsfunnel");
2717 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2719 gst_object_unref (priv->funnel);
2720 priv->funnel = NULL;
2721 g_warning ("Could not add funnel to pipeline");
2725 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2727 g_warning ("Could not add the video output widget to the pipeline");
2731 if (!gst_element_link (priv->funnel, output))
2733 g_warning ("Could not link output sink to funnel");
2734 goto error_output_added;
2737 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2739 g_warning ("Could not start video sink");
2740 goto error_output_added;
2743 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2745 g_warning ("Could not start funnel");
2746 goto error_output_added;
2750 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2753 g_warning ("Could not get request pad from funnel");
2760 gst_element_set_locked_state (priv->funnel, TRUE);
2761 gst_element_set_locked_state (output, TRUE);
2763 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2764 gst_element_set_state (output, GST_STATE_NULL);
2766 gst_bin_remove (GST_BIN (priv->pipeline), output);
2767 gst_element_set_locked_state (output, FALSE);
2771 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2772 priv->funnel = NULL;
2777 /* Called with global lock held */
2779 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2782 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2784 GstPadTemplate *template;
2786 if (!priv->audio_output_added)
2788 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2790 g_warning ("Could not add audio sink to pipeline");
2791 g_object_unref (priv->audio_output);
2792 goto error_add_output;
2795 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2797 g_warning ("Could not start audio sink");
2802 template = gst_element_class_get_pad_template (
2803 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2805 pad = gst_element_request_pad (priv->audio_output,
2806 template, NULL, NULL);
2810 g_warning ("Could not get sink pad from sink");
2817 gst_element_set_locked_state (priv->audio_output, TRUE);
2818 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2819 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2820 priv->audio_output = NULL;
2828 empathy_call_window_update_timer (gpointer user_data)
2830 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2831 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2832 const gchar *status;
2836 time_ = g_timer_elapsed (priv->timer, NULL);
2838 if (priv->call_state == HELD)
2839 status = _("On hold");
2840 else if (!gtk_toggle_tool_button_get_active (
2841 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2844 status = _("Duration");
2846 /* Translators: 'status - minutes:seconds' the caller has been connected */
2847 str = g_strdup_printf (_("%s — %d:%02dm"),
2849 (int) time_ / 60, (int) time_ % 60);
2850 empathy_call_window_status_message (self, str);
2858 EMP_RESPONSE_BALANCE
2862 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2866 switch (response_id)
2868 case GTK_RESPONSE_CLOSE:
2869 gtk_widget_destroy (GTK_WIDGET (info_bar));
2871 case EMP_RESPONSE_BALANCE:
2872 empathy_url_show (GTK_WIDGET (info_bar),
2873 g_object_get_data (G_OBJECT (info_bar), "uri"));
2879 display_error (EmpathyCallWindow *self,
2883 const gchar *details,
2884 const gchar *button_text,
2886 gint button_response)
2888 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2889 GtkWidget *info_bar;
2890 GtkWidget *content_area;
2897 /* Create info bar */
2898 info_bar = gtk_info_bar_new ();
2900 if (button_text != NULL)
2902 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2903 button_text, button_response);
2904 g_object_set_data_full (G_OBJECT (info_bar),
2905 "uri", g_strdup (uri), g_free);
2908 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2909 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
2911 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2913 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2915 /* hbox containing the image and the messages vbox */
2916 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2917 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2920 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2921 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2923 /* vbox containing the main message and the details expander */
2924 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2925 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2928 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2930 label = gtk_label_new (NULL);
2931 gtk_label_set_markup (GTK_LABEL (label), txt);
2932 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2933 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2936 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2939 if (details != NULL)
2941 GtkWidget *expander;
2943 expander = gtk_expander_new (_("Technical Details"));
2945 txt = g_strdup_printf ("<i>%s</i>", details);
2947 label = gtk_label_new (NULL);
2948 gtk_label_set_markup (GTK_LABEL (label), txt);
2949 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2950 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2953 gtk_container_add (GTK_CONTAINER (expander), label);
2954 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2957 g_signal_connect (info_bar, "response",
2958 G_CALLBACK (on_error_infobar_response_cb), NULL);
2960 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2961 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2962 gtk_widget_show_all (info_bar);
2967 media_stream_error_to_txt (EmpathyCallWindow *self,
2968 TpCallChannel *call,
2970 TpMediaStreamError error)
2972 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2973 const gchar *cm = NULL;
2979 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2981 return g_strdup_printf (
2982 _("%s's software does not understand any of the audio formats "
2983 "supported by your computer"),
2984 empathy_contact_get_alias (priv->contact));
2986 return g_strdup_printf (
2987 _("%s's software does not understand any of the video formats "
2988 "supported by your computer"),
2989 empathy_contact_get_alias (priv->contact));
2991 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2992 return g_strdup_printf (
2993 _("Can't establish a connection to %s. "
2994 "One of you might be on a network that does not allow "
2995 "direct connections."),
2996 empathy_contact_get_alias (priv->contact));
2998 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2999 return g_strdup (_("There was a failure on the network"));
3001 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3003 return g_strdup (_("The audio formats necessary for this call "
3004 "are not installed on your computer"));
3006 return g_strdup (_("The video formats necessary for this call "
3007 "are not installed on your computer"));
3009 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3010 tp_connection_parse_object_path (
3011 tp_channel_borrow_connection (TP_CHANNEL (call)),
3014 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3015 "product=Telepathy&component=%s", cm);
3017 result = g_strdup_printf (
3018 _("Something unexpected happened in a Telepathy component. "
3019 "Please <a href=\"%s\">report this bug</a> and attach "
3020 "logs gathered from the 'Debug' window in the Help menu."), url);
3026 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3027 return g_strdup (_("There was a failure in the call engine"));
3029 case TP_MEDIA_STREAM_ERROR_EOS:
3030 return g_strdup (_("The end of the stream was reached"));
3032 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3039 empathy_call_window_stream_error (EmpathyCallWindow *self,
3040 TpCallChannel *call,
3049 desc = media_stream_error_to_txt (self, call, audio, code);
3052 /* No description, use the error message. That's not great as it's not
3053 * localized but it's better than nothing. */
3054 display_error (self, call, icon, title, msg, NULL);
3058 display_error (self, call, icon, title, desc, msg);
3064 empathy_call_window_audio_stream_error (TpCallChannel *call,
3067 EmpathyCallWindow *self)
3069 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3070 "gnome-stock-mic", _("Can't establish audio stream"));
3074 empathy_call_window_video_stream_error (TpCallChannel *call,
3077 EmpathyCallWindow *self)
3079 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3080 "camera-web", _("Can't establish video stream"));
3085 show_balance_error (EmpathyCallWindow *self)
3089 gchar *balance, *tmp;
3090 const gchar *uri, *currency;
3094 g_object_get (self->priv->handler,
3095 "call-channel", &call,
3098 conn = tp_channel_borrow_connection (call);
3099 g_object_unref (call);
3101 uri = tp_connection_get_balance_uri (conn);
3103 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3105 /* unknown balance */
3106 balance = g_strdup ("(--)");
3110 char *money = empathy_format_currency (amount, scale, currency);
3112 balance = g_strdup_printf ("%s %s",
3117 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3119 display_error (self,
3121 _("Sorry, you don’t have enough credit for that call."),
3125 EMP_RESPONSE_BALANCE);
3132 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3135 EmpathyCallWindow *self)
3137 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3138 TpCallChannel *call;
3139 gboolean can_send_video;
3141 if (state == TP_CALL_STATE_ENDED)
3143 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3144 empathy_call_window_disconnected (self, TRUE);
3145 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3146 show_balance_error (self);
3150 if (state != TP_CALL_STATE_ACCEPTED)
3153 if (priv->call_state == CONNECTED)
3156 g_timer_start (priv->timer);
3157 priv->call_state = CONNECTED;
3159 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3161 can_send_video = priv->video_input != NULL &&
3162 empathy_contact_can_voip_video (priv->contact) &&
3163 empathy_camera_monitor_get_available (priv->camera_monitor);
3165 g_object_get (priv->handler, "call-channel", &call, NULL);
3167 if (tp_call_channel_has_dtmf (call))
3168 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3170 if (priv->video_input == NULL)
3171 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3173 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3175 empathy_call_window_show_hangup_button (self, TRUE);
3177 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3179 clutter_actor_hide (priv->video_output);
3180 gtk_widget_show (priv->remote_user_avatar_widget);
3182 g_object_unref (call);
3184 g_mutex_lock (priv->lock);
3186 priv->timer_id = g_timeout_add_seconds (1,
3187 empathy_call_window_update_timer, self);
3189 g_mutex_unlock (priv->lock);
3191 empathy_call_window_update_timer (self);
3193 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3197 empathy_call_window_show_video_output_cb (gpointer user_data)
3199 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3201 if (self->priv->video_output != NULL)
3203 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3204 clutter_actor_show (self->priv->video_output);
3205 clutter_actor_raise_top (self->priv->overlay_bin);
3212 empathy_call_window_check_video_cb (gpointer data)
3214 EmpathyCallWindow *self = data;
3216 if (self->priv->got_video)
3218 self->priv->got_video = FALSE;
3222 /* No video in the last N seconds, display the remote avatar */
3223 empathy_call_window_show_video_output (self, FALSE);
3228 /* Called from the streaming thread */
3230 empathy_call_window_video_probe_cb (GstPad *pad,
3231 GstMiniObject *mini_obj,
3232 EmpathyCallWindow *self)
3235 if (GST_IS_EVENT (mini_obj))
3238 if (G_UNLIKELY (!self->priv->got_video))
3240 /* show the remote video */
3241 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3242 empathy_call_window_show_video_output_cb,
3243 g_object_ref (self), g_object_unref);
3245 self->priv->got_video = TRUE;
3251 /* Called from the streaming thread */
3253 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3254 TfContent *content, GstPad *src, gpointer user_data)
3256 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3257 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3258 gboolean retval = FALSE;
3263 g_mutex_lock (priv->lock);
3265 g_object_get (content, "media-type", &media_type, NULL);
3269 case TP_MEDIA_STREAM_TYPE_AUDIO:
3270 pad = empathy_call_window_get_audio_sink_pad (self, content);
3272 case TP_MEDIA_STREAM_TYPE_VIDEO:
3273 g_idle_add (empathy_call_window_show_video_output_cb, self);
3274 pad = empathy_call_window_get_video_sink_pad (self);
3276 gst_pad_add_data_probe (src,
3277 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3278 if (priv->got_video_src > 0)
3279 g_source_remove (priv->got_video_src);
3280 priv->got_video_src = g_timeout_add_seconds (1,
3281 empathy_call_window_check_video_cb, self);
3284 g_assert_not_reached ();
3290 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3291 g_warning ("Could not link %s sink pad",
3292 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3296 gst_object_unref (pad);
3300 /* If no sink could be linked, try to add fakesink to prevent the whole call
3305 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3307 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3309 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3310 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3311 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3313 gst_element_set_locked_state (fakesink, TRUE);
3314 gst_element_set_state (fakesink, GST_STATE_NULL);
3315 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3319 DEBUG ("Could not link real sink, linked fakesink instead");
3321 gst_object_unref (sinkpad);
3325 gst_object_unref (fakesink);
3330 g_mutex_unlock (priv->lock);
3336 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3339 EmpathyCallWindowPriv *priv = self->priv;
3341 g_assert (priv->audio_output_added == FALSE);
3342 g_assert (priv->audio_output == FALSE);
3344 priv->audio_output = empathy_audio_sink_new ();
3345 g_object_ref_sink (priv->audio_output);
3347 /* volume button to output volume linking */
3348 g_object_bind_property (priv->audio_output, "volume",
3349 priv->volume_button, "value",
3350 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3352 g_object_bind_property_full (content, "requested-output-volume",
3353 priv->audio_output, "volume",
3355 audio_control_volume_to_element,
3356 element_volume_to_audio_control,
3359 /* Link volumes together, sync the current audio input volume property
3360 * back to farstream first */
3361 g_object_bind_property_full (priv->audio_output, "volume",
3362 content, "reported-output-volume",
3363 G_BINDING_SYNC_CREATE,
3364 element_volume_to_audio_control,
3365 audio_control_volume_to_element,
3368 /* For raw audio conferences assume that the producer of the raw data
3369 * has already processed it, so turn off any echo cancellation and any
3370 * other audio improvements that come with it */
3371 empathy_audio_sink_set_echo_cancel (
3372 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3373 !empathy_call_window_content_is_raw (content));
3378 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3379 TfContent *content, gpointer user_data)
3381 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3382 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3384 FsMediaType media_type;
3385 gboolean retval = FALSE;
3387 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3388 g_assert (sink != NULL);
3392 case FS_MEDIA_TYPE_AUDIO:
3394 /* For raw audio conferences assume that the receiver of the raw data
3395 * wants it unprocessed, so turn off any echo cancellation and any
3396 * other audio improvements that come with it */
3397 empathy_audio_src_set_echo_cancel (
3398 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3399 !empathy_call_window_content_is_raw (content));
3401 /* Link volumes together, sync the current audio input volume property
3402 * back to farstream first */
3403 g_object_bind_property_full (content, "requested-input-volume",
3404 priv->audio_input, "volume",
3406 audio_control_volume_to_element,
3407 element_volume_to_audio_control,
3410 g_object_bind_property_full (priv->audio_input, "volume",
3411 content, "reported-input-volume",
3412 G_BINDING_SYNC_CREATE,
3413 element_volume_to_audio_control,
3414 audio_control_volume_to_element,
3417 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3419 g_warning ("Could not add audio source to pipeline");
3423 pad = gst_element_get_static_pad (priv->audio_input, "src");
3426 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3427 g_warning ("Could not get source pad from audio source");
3431 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3433 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3434 gst_object_unref (pad);
3435 g_warning ("Could not link audio source to farsight");
3438 gst_object_unref (pad);
3440 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3442 g_warning ("Could not start audio source");
3443 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3444 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3448 /* Prepare our audio output, not added yet though */
3449 empathy_call_window_prepare_audio_output (self, content);
3453 case FS_MEDIA_TYPE_VIDEO:
3454 if (priv->video_tee != NULL)
3456 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3457 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3459 g_warning ("Could not link video source input pipeline");
3462 gst_object_unref (pad);
3468 g_assert_not_reached ();
3471 gst_object_unref (sink);
3476 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3478 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3479 GstElement *preview;
3481 disable_camera (self);
3483 DEBUG ("remove video input");
3484 preview = priv->video_preview_sink;
3486 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3487 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3488 gst_element_set_state (preview, GST_STATE_NULL);
3490 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3493 g_object_unref (priv->video_input);
3494 priv->video_input = NULL;
3495 g_object_unref (priv->video_tee);
3496 priv->video_tee = NULL;
3497 clutter_actor_destroy (priv->video_preview);
3498 priv->video_preview = NULL;
3500 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3504 start_call (EmpathyCallWindow *self)
3506 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3508 priv->call_started = TRUE;
3509 empathy_call_handler_start_call (priv->handler,
3510 gtk_get_current_event_time ());
3512 if (empathy_call_handler_has_initial_video (priv->handler))
3514 TpCallChannel *call;
3517 g_object_get (priv->handler, "call-channel", &call, NULL);
3518 /* If the call channel isn't set yet we're requesting it, if we're
3519 * requesting it with initial video it should be PENDING_SEND when we get
3522 s = TP_SENDING_STATE_PENDING_SEND;
3524 s = empathy_call_channel_get_video_state (call);
3526 if (s == TP_SENDING_STATE_PENDING_SEND ||
3527 s == TP_SENDING_STATE_SENDING)
3529 /* Enable 'send video' buttons and display the preview */
3530 gtk_toggle_tool_button_set_active (
3531 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3535 gtk_toggle_tool_button_set_active (
3536 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3538 if (priv->video_preview == NULL)
3540 create_video_preview (self);
3541 add_video_preview_to_pipeline (self);
3546 g_object_unref (call);
3551 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3554 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3555 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3556 GstState newstate, pending;
3558 empathy_call_handler_bus_message (priv->handler, bus, message);
3560 switch (GST_MESSAGE_TYPE (message))
3562 case GST_MESSAGE_STATE_CHANGED:
3563 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3565 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3567 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3568 !priv->call_started)
3570 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3571 if (newstate == GST_STATE_PAUSED)
3573 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3574 priv->pipeline_playing = TRUE;
3576 if (priv->start_call_when_playing)
3580 if (priv->video_preview_sink != NULL &&
3581 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3583 gst_message_parse_state_changed (message, NULL, &newstate,
3586 if (newstate == GST_STATE_PLAYING &&
3587 pending == GST_STATE_VOID_PENDING)
3588 empathy_call_window_stop_camera_spinning (self);
3591 case GST_MESSAGE_ERROR:
3593 GError *error = NULL;
3594 GstElement *gst_error;
3598 gst_message_parse_error (message, &error, &debug);
3599 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3601 g_message ("Element error: %s -- %s\n", error->message, debug);
3603 name = gst_element_get_name (gst_error);
3604 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3606 /* Remove the video input and continue */
3607 if (priv->video_input != NULL)
3608 empathy_call_window_remove_video_input (self);
3609 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3613 empathy_call_window_disconnected (self, TRUE);
3616 g_error_free (error);
3619 case GST_MESSAGE_UNKNOWN:
3620 case GST_MESSAGE_EOS:
3621 case GST_MESSAGE_WARNING:
3622 case GST_MESSAGE_INFO:
3623 case GST_MESSAGE_TAG:
3624 case GST_MESSAGE_BUFFERING:
3625 case GST_MESSAGE_STATE_DIRTY:
3626 case GST_MESSAGE_STEP_DONE:
3627 case GST_MESSAGE_CLOCK_PROVIDE:
3628 case GST_MESSAGE_CLOCK_LOST:
3629 case GST_MESSAGE_NEW_CLOCK:
3630 case GST_MESSAGE_STRUCTURE_CHANGE:
3631 case GST_MESSAGE_STREAM_STATUS:
3632 case GST_MESSAGE_APPLICATION:
3633 case GST_MESSAGE_ELEMENT:
3634 case GST_MESSAGE_SEGMENT_START:
3635 case GST_MESSAGE_SEGMENT_DONE:
3636 case GST_MESSAGE_DURATION:
3637 case GST_MESSAGE_ANY:
3646 empathy_call_window_members_changed_cb (TpCallChannel *call,
3647 GHashTable *updates,
3649 TpCallStateReason *reason,
3650 EmpathyCallWindow *self)
3652 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3653 GHashTableIter iter;
3654 gpointer key, value;
3655 gboolean held = FALSE;
3657 g_hash_table_iter_init (&iter, updates);
3658 while (g_hash_table_iter_next (&iter, &key, &value))
3660 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3662 /* This assumes this is a 1-1 call, otherwise one participant
3663 * putting the call on hold wouldn't mean the call is on hold
3671 priv->call_state = HELD;
3672 else if (priv->call_state == HELD)
3673 priv->call_state = CONNECTED;
3677 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3679 EmpathyCallWindow *self)
3681 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3682 TpCallChannel *call;
3684 g_object_get (priv->handler, "call-channel", &call, NULL);
3689 tp_g_signal_connect_object (call, "audio-stream-error",
3690 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3691 tp_g_signal_connect_object (call, "video-stream-error",
3692 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3695 tp_g_signal_connect_object (call, "members-changed",
3696 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3698 g_object_unref (call);
3702 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3704 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3705 TpCallChannel *call;
3707 g_signal_connect (priv->handler, "state-changed",
3708 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3709 g_signal_connect (priv->handler, "conference-added",
3710 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3711 g_signal_connect (priv->handler, "conference-removed",
3712 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3713 g_signal_connect (priv->handler, "closed",
3714 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3715 g_signal_connect (priv->handler, "src-pad-added",
3716 G_CALLBACK (empathy_call_window_src_added_cb), self);
3717 g_signal_connect (priv->handler, "content-added",
3718 G_CALLBACK (empathy_call_window_content_added_cb), self);
3719 g_signal_connect (priv->handler, "content-removed",
3720 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3722 /* We connect to ::call-channel unconditionally since we'll
3723 * get new channels if we hangup and redial or if we reuse the
3725 g_signal_connect (priv->handler, "notify::call-channel",
3726 G_CALLBACK (call_handler_notify_call_cb), self);
3728 g_signal_connect (priv->handler, "framerate-changed",
3729 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3730 g_signal_connect (priv->handler, "resolution-changed",
3731 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3733 g_object_get (priv->handler, "call-channel", &call, NULL);
3736 /* We won't get notify::call-channel for this channel, so
3737 * directly call the callback. */
3738 call_handler_notify_call_cb (priv->handler, NULL, self);
3739 g_object_unref (call);
3744 empathy_call_window_realized_cb (GtkWidget *widget,
3745 EmpathyCallWindow *self)
3749 /* Make the hangup button twice as wide */
3750 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3751 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3753 empathy_call_window_connect_handler (self);
3755 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3759 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3760 EmpathyCallWindow *window)
3762 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3764 if (priv->pipeline != NULL)
3766 if (priv->bus_message_source_id != 0)
3768 g_source_remove (priv->bus_message_source_id);
3769 priv->bus_message_source_id = 0;
3772 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3775 if (priv->call_state == CONNECTING)
3776 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3782 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3785 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3787 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3792 gtk_widget_hide (priv->dtmf_panel);
3793 gtk_widget_hide (menu);
3794 gtk_widget_hide (priv->toolbar);
3798 if (priv->dialpad_was_visible_before_fs)
3799 gtk_widget_show (priv->dtmf_panel);
3801 gtk_widget_show (menu);
3802 gtk_widget_show (priv->toolbar);
3804 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3805 priv->original_height_before_fs);
3810 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3812 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3814 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3815 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3817 if (priv->video_output != NULL)
3820 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3821 priv->video_output, TRUE, TRUE,
3822 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3829 empathy_call_window_state_event_cb (GtkWidget *widget,
3830 GdkEventWindowState *event, EmpathyCallWindow *window)
3832 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3834 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3835 gboolean set_fullscreen = event->new_window_state &
3836 GDK_WINDOW_STATE_FULLSCREEN;
3840 gboolean dialpad_was_visible;
3841 GtkAllocation allocation;
3842 gint original_width, original_height;
3844 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3845 original_width = allocation.width;
3846 original_height = allocation.height;
3848 g_object_get (priv->dtmf_panel,
3849 "visible", &dialpad_was_visible,
3852 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3853 priv->original_width_before_fs = original_width;
3854 priv->original_height_before_fs = original_height;
3856 if (priv->video_output_motion_handler_id == 0 &&
3857 priv->video_output != NULL)
3859 priv->video_output_motion_handler_id = g_signal_connect (
3860 G_OBJECT (priv->video_container), "motion-notify-event",
3861 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3867 disconnect_video_output_motion_handler (window);
3870 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3872 show_controls (window, set_fullscreen);
3873 show_borders (window, set_fullscreen);
3874 gtk_action_set_stock_id (priv->menu_fullscreen,
3875 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3876 priv->is_fullscreen = set_fullscreen;
3883 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3886 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3887 int w, h, dialpad_width;
3888 GtkAllocation allocation;
3890 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3891 w = allocation.width;
3892 h = allocation.height;
3894 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3898 gtk_widget_show (priv->dtmf_panel);
3904 gtk_widget_hide (priv->dtmf_panel);
3908 gtk_window_resize (GTK_WINDOW (window), w, h);
3912 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3915 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3916 TpCallChannel *call;
3918 priv->sending_video = (state == CAMERA_STATE_ON);
3920 if (state == CAMERA_STATE_ON)
3922 /* When we start sending video, we want to show the video preview by
3924 display_video_preview (window, TRUE);
3928 display_video_preview (window, FALSE);
3931 if (priv->call_state != CONNECTED)
3934 g_object_get (priv->handler, "call-channel", &call, NULL);
3935 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3936 empathy_call_channel_send_video (call, priv->sending_video);
3937 g_object_unref (call);
3941 empathy_call_window_hangup_cb (gpointer object,
3942 EmpathyCallWindow *self)
3944 /* stopping the call will put it the ENDED state and
3945 * from state_changed_cb we'll reconfigure the window
3947 empathy_call_handler_stop_call (self->priv->handler);
3951 empathy_call_window_restart_call (EmpathyCallWindow *window)
3953 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3955 /* Remove error info bars */
3956 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3957 (GtkCallback) gtk_widget_destroy, NULL);
3959 create_video_output_widget (window);
3960 priv->outgoing = TRUE;
3961 empathy_call_window_set_state_connecting (window);
3963 if (priv->pipeline_playing)
3964 start_call (window);
3966 /* call will be started when the pipeline is ready */
3967 priv->start_call_when_playing = TRUE;
3969 empathy_call_window_setup_avatars (window, priv->handler);
3971 empathy_call_window_show_hangup_button (window, TRUE);
3975 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3976 EmpathyCallWindow *window)
3980 active = gtk_toggle_tool_button_get_active (button);
3982 empathy_call_window_show_dialpad (window, active);
3986 empathy_call_window_fullscreen_cb (gpointer object,
3987 EmpathyCallWindow *window)
3989 empathy_call_window_fullscreen_toggle (window);
3993 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3995 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3997 if (priv->is_fullscreen)
3998 gtk_window_unfullscreen (GTK_WINDOW (window));
4000 gtk_window_fullscreen (GTK_WINDOW (window));
4004 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4005 GdkEventButton *event, EmpathyCallWindow *window)
4007 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4009 empathy_call_window_video_menu_popup (window, event->button);
4017 empathy_call_window_key_press_cb (GtkWidget *video_output,
4018 GdkEventKey *event, EmpathyCallWindow *window)
4020 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4022 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4024 /* Since we are in fullscreen mode, toggling will bring us back to
4026 empathy_call_window_fullscreen_toggle (window);
4034 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4035 GdkEventMotion *event, EmpathyCallWindow *window)
4037 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4039 if (priv->is_fullscreen)
4041 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4043 /* Show the bottom toolbar */
4044 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4051 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4055 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4057 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4059 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4060 button, gtk_get_current_event_time ());
4061 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4065 empathy_call_window_status_message (EmpathyCallWindow *self,
4068 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4072 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4074 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4076 return priv->ui_manager;
4079 EmpathyGstAudioSrc *
4080 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4082 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4084 return (EmpathyGstAudioSrc *) priv->audio_input;
4087 EmpathyGstVideoSrc *
4088 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4090 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4094 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4095 const gchar *device)
4097 EmpathyGstVideoSrc *video;
4100 /* Restart the camera only if it's already running */
4101 running = (self->priv->video_preview != NULL);
4102 video = empathy_call_window_get_video_src (self);
4105 empathy_call_window_play_camera (self, FALSE);
4107 empathy_video_src_change_device (video, device);
4110 empathy_call_window_play_camera (self, TRUE);