2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <gdk/gdkkeysyms.h>
31 #include <glib/gi18n.h>
33 #include <clutter/clutter.h>
34 #include <clutter-gtk/clutter-gtk.h>
35 #include <clutter-gst/clutter-gst.h>
37 #include <telepathy-glib/util.h>
38 #include <telepathy-farstream/telepathy-farstream.h>
39 #include <telepathy-glib/util.h>
41 #include <farstream/fs-element-added-notifier.h>
42 #include <farstream/fs-utils.h>
44 #include <libempathy/empathy-camera-monitor.h>
45 #include <libempathy/empathy-gsettings.h>
46 #include <libempathy/empathy-tp-contact-factory.h>
47 #include <libempathy/empathy-request-util.h>
48 #include <libempathy/empathy-utils.h>
50 #include <libempathy-gtk/empathy-avatar-image.h>
51 #include <libempathy-gtk/empathy-dialpad-widget.h>
52 #include <libempathy-gtk/empathy-ui-utils.h>
53 #include <libempathy-gtk/empathy-sound-manager.h>
54 #include <libempathy-gtk/empathy-geometry.h>
55 #include <libempathy-gtk/empathy-images.h>
56 #include <libempathy-gtk/empathy-call-utils.h>
58 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
59 #include <libempathy/empathy-debug.h>
61 #include "empathy-call-window.h"
62 #include "empathy-call-window-fullscreen.h"
63 #include "empathy-call-factory.h"
64 #include "empathy-video-widget.h"
65 #include "empathy-about-dialog.h"
66 #include "empathy-audio-src.h"
67 #include "empathy-audio-sink.h"
68 #include "empathy-video-src.h"
69 #include "empathy-mic-menu.h"
70 #include "empathy-preferences.h"
71 #include "empathy-rounded-actor.h"
72 #include "empathy-rounded-rectangle.h"
73 #include "empathy-rounded-texture.h"
74 #include "empathy-camera-menu.h"
76 #define CONTENT_HBOX_BORDER_WIDTH 6
77 #define CONTENT_HBOX_SPACING 3
78 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
80 #define SELF_VIDEO_SECTION_WIDTH 120
81 #define SELF_VIDEO_SECTION_HEIGHT 90
82 #define SELF_VIDEO_SECTION_MARGIN 2
83 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
85 #define FLOATING_TOOLBAR_OPACITY 192
86 #define FLOATING_TOOLBAR_SPACING 20
88 /* The avatar's default width and height are set to the same value because we
89 want a square icon. */
90 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
91 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
92 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
94 #define SMALL_TOOLBAR_SIZE 36
96 /* If an video input error occurs, the error message will start with "v4l" */
97 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
99 /* The time interval in milliseconds between 2 outgoing rings */
100 #define MS_BETWEEN_RING 500
102 /* The roundedness of preview box and placeholders */
103 #define PREVIEW_ROUND_FACTOR 16
105 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
108 PROP_CALL_HANDLER = 1,
112 RINGING, /* Incoming call */
113 CONNECTING, /* Outgoing call */
114 CONNECTED, /* Connected */
115 HELD, /* Connected, but on hold */
116 DISCONNECTED, /* Disconnected */
117 REDIALING /* Redialing (special case of CONNECTING) */
121 CAMERA_STATE_OFF = 0,
127 PREVIEW_POS_TOP_LEFT,
128 PREVIEW_POS_TOP_RIGHT,
129 PREVIEW_POS_BOTTOM_LEFT,
130 PREVIEW_POS_BOTTOM_RIGHT,
133 struct _EmpathyCallWindowPriv
135 gboolean dispose_has_run;
136 EmpathyCallHandler *handler;
138 EmpathyContact *contact;
140 EmpathyCameraMonitor *camera_monitor;
145 GtkUIManager *ui_manager;
146 GtkWidget *errors_vbox;
147 /* widget displays the video received from the remote user. This widget is
148 * alive only during call. */
149 ClutterActor *video_output;
150 ClutterActor *video_preview;
151 ClutterActor *drag_preview;
152 ClutterActor *preview_shown_button;
153 ClutterActor *preview_hidden_button;
154 ClutterActor *preview_rectangle1;
155 ClutterActor *preview_rectangle2;
156 ClutterActor *preview_rectangle3;
157 ClutterActor *preview_rectangle4;
158 ClutterActor *preview_spinner_actor;
159 GtkWidget *preview_spinner_widget;
160 GtkWidget *video_container;
161 GtkWidget *remote_user_avatar_widget;
162 GtkWidget *remote_user_avatar_toolbar;
163 GtkWidget *remote_user_name_toolbar;
164 GtkWidget *status_label;
165 GtkWidget *hangup_button;
166 GtkWidget *audio_call_button;
167 GtkWidget *video_call_button;
168 GtkWidget *mic_button;
169 GtkWidget *volume_button;
170 GtkWidget *camera_button;
171 GtkWidget *dialpad_button;
173 GtkWidget *bottom_toolbar;
174 ClutterActor *floating_toolbar;
176 GtkAction *menu_fullscreen;
177 GtkAction *menu_swap_camera;
179 ClutterState *transitions;
181 /* The main box covering all the stage, contaning remote avatar/video */
182 ClutterActor *video_box;
183 ClutterLayoutManager *video_layout;
185 /* A Box layout manager containing a bin for previews
186 * and the floating toolbar */
187 ClutterActor *overlay_box;
188 ClutterLayoutManager *overlay_layout;
190 /* Bin layout for the previews */
191 ClutterActor *preview_box;
192 ClutterLayoutManager *preview_layout;
194 /* Coordinates of the preview drag event's start. */
195 PreviewPosition preview_pos;
197 /* We keep a reference on the hbox which contains the main content so we can
198 easilly repack everything when toggling fullscreen */
199 GtkWidget *content_hbox;
201 /* These are used to accept or reject an incoming call when the status
203 GtkWidget *incoming_call_dialog;
204 TpCallChannel *pending_channel;
205 TpChannelDispatchOperation *pending_cdo;
206 TpAddDispatchOperationContext *pending_context;
208 gulong video_output_motion_handler_id;
209 guint bus_message_source_id;
211 GtkWidget *dtmf_panel;
214 GtkWidget *details_vbox;
215 GtkWidget *vcodec_encoding_label;
216 GtkWidget *acodec_encoding_label;
217 GtkWidget *vcodec_decoding_label;
218 GtkWidget *acodec_decoding_label;
220 GtkWidget *audio_remote_candidate_label;
221 GtkWidget *audio_local_candidate_label;
222 GtkWidget *video_remote_candidate_label;
223 GtkWidget *video_local_candidate_label;
224 GtkWidget *video_remote_candidate_info_img;
225 GtkWidget *video_local_candidate_info_img;
226 GtkWidget *audio_remote_candidate_info_img;
227 GtkWidget *audio_local_candidate_info_img;
229 GstElement *video_input;
230 GstElement *video_preview_sink;
231 GstElement *video_output_sink;
232 GstElement *audio_input;
233 GstElement *audio_output;
234 gboolean audio_output_added;
235 GstElement *pipeline;
236 GstElement *video_tee;
246 gboolean call_started;
247 gboolean sending_video;
248 CameraState camera_state;
250 EmpathyCallWindowFullscreen *fullscreen;
251 gboolean is_fullscreen;
256 guint inactivity_src;
258 /* Those fields represent the state of the window before it actually was in
260 gboolean dialpad_was_visible_before_fs;
261 gint original_width_before_fs;
262 gint original_height_before_fs;
264 gint x, y, w, h, dialpad_width;
267 /* TRUE if the call should be started when the pipeline is playing */
268 gboolean start_call_when_playing;
269 /* TRUE if we requested to set the pipeline in the playing state */
270 gboolean pipeline_playing;
272 EmpathySoundManager *sound_mgr;
275 EmpathyMicMenu *mic_menu;
276 EmpathyCameraMenu *camera_menu;
279 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
281 static void empathy_call_window_realized_cb (GtkWidget *widget,
282 EmpathyCallWindow *window);
284 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
285 GdkEvent *event, EmpathyCallWindow *window);
287 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
288 GdkEventWindowState *event, EmpathyCallWindow *window);
290 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
293 static void empathy_call_window_hangup_cb (gpointer object,
294 EmpathyCallWindow *window);
296 static void empathy_call_window_fullscreen_cb (gpointer object,
297 EmpathyCallWindow *window);
299 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
301 static gboolean empathy_call_window_video_button_press_cb (
302 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
304 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
305 GdkEventKey *event, EmpathyCallWindow *window);
307 static gboolean empathy_call_window_video_output_motion_notify (
308 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
310 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
313 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
315 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
316 EmpathyCallWindow *window);
318 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
320 static void empathy_call_window_status_message (EmpathyCallWindow *window,
323 static gboolean empathy_call_window_bus_message (GstBus *bus,
324 GstMessage *message, gpointer user_data);
327 make_background_transparent (GtkClutterActor *actor)
329 GdkRGBA transparent = { 0., 0., 0., 0. };
332 widget = gtk_clutter_actor_get_widget (actor);
333 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
337 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
340 gtk_widget_set_visible (self->priv->hangup_button, show);
341 gtk_widget_set_visible (self->priv->audio_call_button, !show);
342 gtk_widget_set_visible (self->priv->video_call_button, !show);
346 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
347 EmpathyCallWindow *self)
349 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
350 empathy_call_window_restart_call (self);
354 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
355 EmpathyCallWindow *self)
357 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
358 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
359 empathy_call_window_restart_call (self);
363 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
365 EmpathyCallWindow *self)
370 g_object_get (self->priv->handler, "call-channel", &call, NULL);
372 tones[0] = tp_dtmf_event_to_char (event);
374 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
376 g_object_unref (call);
380 empathy_call_window_raise_actors (EmpathyCallWindow *self)
382 clutter_actor_raise_top (self->priv->floating_toolbar);
384 clutter_actor_raise_top (self->priv->preview_rectangle1);
385 clutter_actor_raise_top (self->priv->preview_rectangle2);
386 clutter_actor_raise_top (self->priv->preview_rectangle3);
387 clutter_actor_raise_top (self->priv->preview_rectangle4);
391 empathy_call_window_show_video_output (EmpathyCallWindow *self,
394 if (self->priv->video_output != NULL)
395 g_object_set (self->priv->video_output, "visible", show, NULL);
397 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
399 empathy_call_window_raise_actors (self);
403 create_video_output_widget (EmpathyCallWindow *self)
405 EmpathyCallWindowPriv *priv = GET_PRIV (self);
407 g_assert (priv->video_output == NULL);
408 g_assert (priv->pipeline != NULL);
410 priv->video_output = clutter_texture_new ();
412 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
415 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
416 if (priv->video_output_sink == NULL)
417 g_error ("Missing cluttersink");
419 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
421 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
424 gtk_widget_add_events (priv->video_container,
425 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
426 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
427 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
431 create_video_input (EmpathyCallWindow *self)
433 EmpathyCallWindowPriv *priv = GET_PRIV (self);
435 g_assert (priv->video_input == NULL);
436 priv->video_input = empathy_video_src_new ();
437 gst_object_ref (priv->video_input);
438 gst_object_sink (priv->video_input);
442 audio_control_volume_to_element (GBinding *binding,
443 const GValue *source_value,
444 GValue *target_value,
447 /* AudioControl volume is 0-255, with -1 for unknown */
450 hv = g_value_get_int (source_value);
455 g_value_set_double (target_value, hv/255.0);
461 element_volume_to_audio_control (GBinding *binding,
462 const GValue *source_value,
463 GValue *target_value,
468 ev = g_value_get_double (source_value);
469 ev = CLAMP (ev, 0.0, 1.0);
471 g_value_set_int (target_value, ev * 255);
476 create_audio_input (EmpathyCallWindow *self)
478 EmpathyCallWindowPriv *priv = GET_PRIV (self);
480 g_assert (priv->audio_input == NULL);
481 priv->audio_input = empathy_audio_src_new ();
482 gst_object_ref (priv->audio_input);
483 gst_object_sink (priv->audio_input);
485 g_object_bind_property (priv->mic_button, "active",
486 priv->audio_input, "mute",
487 G_BINDING_BIDIRECTIONAL |
488 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
492 add_video_preview_to_pipeline (EmpathyCallWindow *self)
494 EmpathyCallWindowPriv *priv = GET_PRIV (self);
497 g_assert (priv->video_preview != NULL);
498 g_assert (priv->pipeline != NULL);
499 g_assert (priv->video_input != NULL);
500 g_assert (priv->video_tee != NULL);
502 preview = priv->video_preview_sink;
504 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
506 g_warning ("Could not add video input to pipeline");
510 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
512 g_warning ("Could not add video preview to pipeline");
516 if (!gst_element_link (priv->video_input, priv->video_tee))
518 g_warning ("Could not link video input to video tee");
522 if (!gst_element_link (priv->video_tee, preview))
524 g_warning ("Could not link video tee to video preview");
530 empathy_call_window_disable_camera_cb (GtkAction *action,
531 EmpathyCallWindow *self)
533 clutter_actor_destroy (self->priv->preview_hidden_button);
535 gtk_toggle_tool_button_set_active (
536 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
540 empathy_call_window_minimise_camera_cb (GtkAction *action,
541 EmpathyCallWindow *self)
543 clutter_actor_hide (self->priv->video_preview);
544 clutter_actor_show (self->priv->preview_hidden_button);
548 empathy_call_window_maximise_camera_cb (GtkAction *action,
549 EmpathyCallWindow *self)
551 clutter_actor_show (self->priv->video_preview);
552 clutter_actor_hide (self->priv->preview_hidden_button);
556 empathy_call_window_swap_camera_cb (GtkAction *action,
557 EmpathyCallWindow *self)
559 const GList *cameras, *l;
562 DEBUG ("Swapping the camera");
564 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
565 current_cam = empathy_video_src_dup_device (
566 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
568 for (l = cameras; l != NULL; l = l->next)
570 EmpathyCamera *camera = l->data;
572 if (!tp_strdiff (camera->device, current_cam))
577 next = l->next->data;
579 next = cameras->data;
581 /* EmpathyCameraMenu will update itself and do the actual change
583 g_settings_set_string (self->priv->settings,
584 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
591 g_free (current_cam);
595 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
596 EmpathyCamera *camera,
597 EmpathyCallWindow *self)
599 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
601 gtk_action_set_visible (self->priv->menu_swap_camera,
602 g_list_length ((GList *) cameras) >= 2);
606 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
607 EmpathyCamera *camera,
608 EmpathyCallWindow *self)
610 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
612 gtk_action_set_visible (self->priv->menu_swap_camera,
613 g_list_length ((GList *) cameras) >= 2);
617 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
618 EmpathyCallWindow *self)
622 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
624 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
625 0, gtk_get_current_event_time ());
626 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
630 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
631 EmpathyCallWindow *self)
635 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
636 "/preview-hidden-menu");
637 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
638 0, gtk_get_current_event_time ());
639 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
642 static ClutterActor *
643 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
644 ClutterBinAlignment x,
645 ClutterBinAlignment y)
647 ClutterActor *rectangle;
649 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
650 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
651 PREVIEW_ROUND_FACTOR));
653 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
655 clutter_actor_hide (rectangle);
661 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
665 self->priv->preview_layout = clutter_bin_layout_new (
666 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
667 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
669 clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (self->priv->overlay_layout),
670 box, TRUE, TRUE, TRUE,
671 CLUTTER_BOX_ALIGNMENT_CENTER, CLUTTER_BOX_ALIGNMENT_START);
673 self->priv->preview_rectangle1 =
674 empathy_call_window_create_preview_rectangle (self,
675 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
676 self->priv->preview_rectangle2 =
677 empathy_call_window_create_preview_rectangle (self,
678 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
679 self->priv->preview_rectangle3 =
680 empathy_call_window_create_preview_rectangle (self,
681 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
682 self->priv->preview_rectangle4 =
683 empathy_call_window_create_preview_rectangle (self,
684 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
688 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
691 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
692 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
693 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
694 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
698 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
703 guint ret_x = 0, ret_y = 0;
706 if (!clutter_actor_has_allocation (self->priv->preview_box))
709 clutter_actor_get_geometry (self->priv->preview_box, &box);
713 case PREVIEW_POS_TOP_LEFT:
714 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
716 case PREVIEW_POS_TOP_RIGHT:
717 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
718 - SELF_VIDEO_SECTION_WIDTH;
719 ret_y = SELF_VIDEO_SECTION_MARGIN;
721 case PREVIEW_POS_BOTTOM_LEFT:
722 ret_x = SELF_VIDEO_SECTION_MARGIN;
723 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
724 - SELF_VIDEO_SECTION_HEIGHT;
726 case PREVIEW_POS_BOTTOM_RIGHT:
727 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
728 - SELF_VIDEO_SECTION_WIDTH;
729 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
730 - SELF_VIDEO_SECTION_HEIGHT;
733 g_warn_if_reached ();
744 static PreviewPosition
745 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
750 PreviewPosition pos = PREVIEW_POS_NONE;
752 if (!clutter_actor_has_allocation (self->priv->preview_box))
755 clutter_actor_get_geometry (self->priv->preview_box, &box);
757 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
758 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
759 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
760 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
762 pos = PREVIEW_POS_TOP_LEFT;
764 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
765 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
766 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
767 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
769 pos = PREVIEW_POS_TOP_RIGHT;
771 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
772 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
773 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
774 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
776 pos = PREVIEW_POS_BOTTOM_LEFT;
778 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
779 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
780 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
781 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
783 pos = PREVIEW_POS_BOTTOM_RIGHT;
789 static ClutterActor *
790 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
793 ClutterActor *rectangle;
797 case PREVIEW_POS_TOP_LEFT:
798 rectangle = self->priv->preview_rectangle1;
800 case PREVIEW_POS_TOP_RIGHT:
801 rectangle = self->priv->preview_rectangle3;
803 case PREVIEW_POS_BOTTOM_LEFT:
804 rectangle = self->priv->preview_rectangle2;
806 case PREVIEW_POS_BOTTOM_RIGHT:
807 rectangle = self->priv->preview_rectangle4;
817 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
820 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
822 DEBUG ("moving the video preview to %d", pos);
824 self->priv->preview_pos = pos;
828 case PREVIEW_POS_TOP_LEFT:
829 clutter_bin_layout_set_alignment (layout,
830 self->priv->video_preview,
831 CLUTTER_BIN_ALIGNMENT_START,
832 CLUTTER_BIN_ALIGNMENT_START);
834 case PREVIEW_POS_TOP_RIGHT:
835 clutter_bin_layout_set_alignment (layout,
836 self->priv->video_preview,
837 CLUTTER_BIN_ALIGNMENT_END,
838 CLUTTER_BIN_ALIGNMENT_START);
840 case PREVIEW_POS_BOTTOM_LEFT:
841 clutter_bin_layout_set_alignment (layout,
842 self->priv->video_preview,
843 CLUTTER_BIN_ALIGNMENT_START,
844 CLUTTER_BIN_ALIGNMENT_END);
846 case PREVIEW_POS_BOTTOM_RIGHT:
847 clutter_bin_layout_set_alignment (layout,
848 self->priv->video_preview,
849 CLUTTER_BIN_ALIGNMENT_END,
850 CLUTTER_BIN_ALIGNMENT_END);
853 g_warn_if_reached ();
856 g_settings_set_enum (self->priv->settings, "camera-position", pos);
860 _clutter_color_from_rgba (ClutterColor *color,
863 color->red = (guint8) floor (rgba->red * 255);
864 color->green = (guint8) floor (rgba->green * 255);
865 color->blue = (guint8) floor (rgba->blue * 255);
866 color->alpha = (guint8) floor (rgba->alpha * 255);
870 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
873 ClutterActor *rectangle;
874 GtkStyleContext *context;
876 ClutterColor color, highlight;
878 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
879 context = gtk_widget_get_style_context (GTK_WIDGET (self));
880 gtk_style_context_get_color (context, 0, &rgba);
882 _clutter_color_from_rgba (&color, &rgba);
883 clutter_color_shade (&color, 1.4, &highlight);
885 empathy_rounded_rectangle_set_border_width (
886 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
887 empathy_rounded_rectangle_set_border_color (
888 EMPATHY_ROUNDED_RECTANGLE (rectangle), &highlight);
892 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
893 ClutterActor *rectangle)
895 GtkStyleContext *context;
897 ClutterColor color, darker;
899 context = gtk_widget_get_style_context (GTK_WIDGET (self));
900 gtk_style_context_get_background_color (context, 0, &rgba);
902 _clutter_color_from_rgba (&color, &rgba);
903 clutter_color_shade (&color, 0.55, &darker);
905 empathy_rounded_rectangle_set_border_width (
906 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
907 empathy_rounded_rectangle_set_border_color (
908 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
912 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
914 ClutterActor *rectangle;
916 rectangle = empathy_call_window_get_preview_rectangle (self,
917 self->priv->preview_pos);
919 /* We don't want to darken the rectangle where the preview
922 if (self->priv->preview_rectangle1 != rectangle)
923 empathy_call_window_darken_preview_rectangle (self,
924 self->priv->preview_rectangle1);
926 if (self->priv->preview_rectangle2 != rectangle)
927 empathy_call_window_darken_preview_rectangle (self,
928 self->priv->preview_rectangle2);
930 if (self->priv->preview_rectangle3 != rectangle)
931 empathy_call_window_darken_preview_rectangle (self,
932 self->priv->preview_rectangle3);
934 if (self->priv->preview_rectangle4 != rectangle)
935 empathy_call_window_darken_preview_rectangle (self,
936 self->priv->preview_rectangle4);
940 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
944 ClutterModifierType modifiers,
945 EmpathyCallWindow *self)
947 ClutterActor *stage = clutter_actor_get_stage (actor);
950 self->priv->drag_preview = clutter_clone_new (actor);
952 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
953 self->priv->drag_preview);
955 clutter_actor_transform_stage_point (actor, event_x, event_y,
958 clutter_actor_set_position (self->priv->drag_preview,
959 event_x - rel_x, event_y - rel_y);
961 clutter_drag_action_set_drag_handle (action,
962 self->priv->drag_preview);
964 clutter_actor_set_opacity (actor, 0);
965 clutter_actor_hide (self->priv->preview_shown_button);
967 empathy_call_window_show_preview_rectangles (self, TRUE);
968 empathy_call_window_darken_preview_rectangles (self);
972 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
975 clutter_actor_set_opacity (actor, 255);
979 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
983 ClutterModifierType modifiers,
984 EmpathyCallWindow *self)
989 /* Get the position before destroying the drag actor, otherwise the
990 * preview_box allocation won't be valid and we won't be able to
991 * calculate the position. */
992 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
994 empathy_call_window_get_preview_coordinates (self,
995 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
998 /* Move the preview to the destination and destroy it afterwards */
999 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
1002 "signal-swapped-after::completed",
1003 clutter_actor_destroy, self->priv->drag_preview,
1004 "signal-swapped-after::completed",
1005 clutter_actor_show, self->priv->preview_shown_button,
1006 "signal::completed",
1007 empathy_call_window_on_animation_completed_cb, actor,
1010 self->priv->drag_preview = NULL;
1012 if (pos != PREVIEW_POS_NONE)
1013 empathy_call_window_move_video_preview (self, pos);
1015 empathy_call_window_show_preview_rectangles (self, FALSE);
1019 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1020 ClutterActor *actor,
1023 EmpathyCallWindow *self)
1025 PreviewPosition pos;
1026 gfloat event_x, event_y;
1028 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1030 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1032 if (pos != PREVIEW_POS_NONE)
1033 empathy_call_window_highlight_preview_rectangle (self, pos);
1035 empathy_call_window_darken_preview_rectangles (self);
1039 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1040 ClutterCrossingEvent *event,
1041 EmpathyCallWindow *self)
1043 ClutterActor *rectangle;
1045 rectangle = empathy_call_window_get_preview_rectangle (self,
1046 self->priv->preview_pos);
1048 empathy_call_window_highlight_preview_rectangle (self,
1049 self->priv->preview_pos);
1051 clutter_actor_show (rectangle);
1057 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1058 ClutterCrossingEvent *event,
1059 EmpathyCallWindow *self)
1061 ClutterActor *rectangle;
1063 rectangle = empathy_call_window_get_preview_rectangle (self,
1064 self->priv->preview_pos);
1066 empathy_call_window_darken_preview_rectangle (self, rectangle);
1068 clutter_actor_hide (rectangle);
1074 create_video_preview (EmpathyCallWindow *self)
1076 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1077 ClutterLayoutManager *layout;
1078 ClutterActor *preview;
1080 ClutterAction *action;
1082 PreviewPosition pos;
1084 g_assert (priv->video_preview == NULL);
1086 pos = g_settings_get_enum (priv->settings, "camera-position");
1088 preview = empathy_rounded_texture_new ();
1089 clutter_actor_set_size (preview,
1090 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1092 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1093 if (priv->video_preview_sink == NULL)
1094 g_error ("Missing cluttersink, check your clutter-gst installation");
1095 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1096 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1098 /* Add a little offset to the video preview */
1099 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1100 CLUTTER_BIN_ALIGNMENT_CENTER);
1101 priv->video_preview = clutter_box_new (layout);
1102 clutter_actor_set_size (priv->video_preview,
1103 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1104 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1106 /* Spinner for when changing the camera device */
1107 priv->preview_spinner_widget = gtk_spinner_new ();
1108 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1110 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1111 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1112 gtk_widget_show (priv->preview_spinner_widget);
1115 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1116 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1117 priv->preview_spinner_widget);
1118 clutter_actor_set_size (priv->preview_spinner_actor,
1119 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1120 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1121 clutter_actor_hide (priv->preview_spinner_actor);
1123 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1125 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1126 priv->preview_spinner_actor);
1128 g_object_set (priv->video_preview_sink,
1133 /* Translators: this is an "Info" label. It should be as short
1135 button = gtk_button_new_with_label (_("i"));
1136 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (button);
1137 clutter_actor_set_size (b, 24, 24);
1138 clutter_actor_set_margin_right (b, 4);
1139 clutter_actor_set_margin_bottom (b, 2);
1140 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1142 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1143 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1145 g_signal_connect (button, "clicked",
1146 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1149 /* Translators: this is an "Info" label. It should be as short
1151 button = gtk_button_new_with_label (_("i"));
1152 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (button);
1153 clutter_actor_set_size (b, 24, 24);
1154 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1156 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1157 priv->preview_hidden_button,
1158 CLUTTER_BIN_ALIGNMENT_START,
1159 CLUTTER_BIN_ALIGNMENT_END);
1161 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1163 clutter_actor_hide (priv->preview_hidden_button);
1165 g_signal_connect (button, "clicked",
1166 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1169 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1170 priv->video_preview,
1171 CLUTTER_BIN_ALIGNMENT_START,
1172 CLUTTER_BIN_ALIGNMENT_END);
1174 empathy_call_window_move_video_preview (self, pos);
1176 action = clutter_drag_action_new ();
1177 g_signal_connect (action, "drag-begin",
1178 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1179 g_signal_connect (action, "drag-end",
1180 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1181 g_signal_connect (action, "drag-motion",
1182 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1184 g_signal_connect (preview, "enter-event",
1185 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1186 g_signal_connect (preview, "leave-event",
1187 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1189 clutter_actor_add_action (preview, action);
1190 clutter_actor_set_reactive (preview, TRUE);
1191 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1195 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1197 clutter_actor_show (self->priv->preview_spinner_actor);
1198 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1202 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1204 clutter_actor_hide (self->priv->preview_spinner_actor);
1205 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1209 empathy_call_window_play_camera (EmpathyCallWindow *self,
1212 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1213 GstElement *preview;
1216 if (priv->video_preview == NULL)
1218 create_video_preview (self);
1219 add_video_preview_to_pipeline (self);
1224 state = GST_STATE_PLAYING;
1228 empathy_call_window_start_camera_spinning (self);
1229 state = GST_STATE_NULL;
1232 preview = priv->video_preview_sink;
1234 gst_element_set_state (preview, state);
1235 gst_element_set_state (priv->video_tee, state);
1236 gst_element_set_state (priv->video_input, state);
1240 display_video_preview (EmpathyCallWindow *self,
1243 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1245 if (priv->video_preview == NULL)
1247 create_video_preview (self);
1248 add_video_preview_to_pipeline (self);
1253 /* Display the video preview */
1254 DEBUG ("Show video preview");
1256 empathy_call_window_play_camera (self, TRUE);
1257 clutter_actor_show (priv->video_preview);
1258 clutter_actor_raise_top (priv->floating_toolbar);
1262 /* Hide the video preview */
1263 DEBUG ("Hide video preview");
1265 if (priv->video_preview != NULL)
1267 clutter_actor_hide (priv->video_preview);
1268 empathy_call_window_play_camera (self, FALSE);
1274 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1276 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1278 empathy_call_window_status_message (window, _("Connecting…"));
1279 priv->call_state = CONNECTING;
1281 /* Show the toolbar */
1282 clutter_state_set_state (priv->transitions, "fade-in");
1285 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1286 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1290 disable_camera (EmpathyCallWindow *self)
1292 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1294 if (priv->camera_state == CAMERA_STATE_OFF)
1297 DEBUG ("Disable camera");
1299 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1301 priv->camera_state = CAMERA_STATE_OFF;
1305 enable_camera (EmpathyCallWindow *self)
1307 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1309 if (priv->camera_state == CAMERA_STATE_ON)
1312 if (priv->video_input == NULL)
1314 DEBUG ("Can't enable camera, no input");
1318 DEBUG ("Enable camera");
1320 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1322 priv->camera_state = CAMERA_STATE_ON;
1326 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1327 EmpathyCallWindow *self)
1329 if (gtk_toggle_tool_button_get_active (toggle))
1330 enable_camera (self);
1332 disable_camera (self);
1336 create_pipeline (EmpathyCallWindow *self)
1338 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1341 g_assert (priv->pipeline == NULL);
1343 priv->pipeline = gst_pipeline_new (NULL);
1344 priv->pipeline_playing = FALSE;
1346 priv->video_tee = gst_element_factory_make ("tee", NULL);
1347 gst_object_ref (priv->video_tee);
1348 gst_object_sink (priv->video_tee);
1350 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1352 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1353 priv->bus_message_source_id = gst_bus_add_watch (bus,
1354 empathy_call_window_bus_message, self);
1356 g_object_unref (bus);
1360 empathy_call_window_settings_cb (GtkAction *action,
1361 EmpathyCallWindow *self)
1363 gchar *args = g_strdup_printf ("-p %s",
1364 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1366 empathy_launch_program (BIN_DIR, "empathy", args);
1372 empathy_call_window_contents_cb (GtkAction *action,
1373 EmpathyCallWindow *self)
1375 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1379 empathy_call_window_debug_cb (GtkAction *action,
1380 EmpathyCallWindow *self)
1382 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1386 empathy_call_window_about_cb (GtkAction *action,
1387 EmpathyCallWindow *self)
1389 empathy_about_dialog_new (GTK_WINDOW (self));
1393 empathy_call_window_toolbar_timeout (gpointer data)
1395 EmpathyCallWindow *self = data;
1397 /* We don't want to hide the toolbar if we're not in a call, as
1398 * to show the call status all the time. */
1399 if (self->priv->call_state != CONNECTING &&
1400 self->priv->call_state != DISCONNECTED)
1401 clutter_state_set_state (self->priv->transitions, "fade-out");
1407 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1409 EmpathyCallWindow *self)
1411 clutter_state_set_state (self->priv->transitions, "fade-in");
1413 if (self->priv->inactivity_src > 0)
1414 g_source_remove (self->priv->inactivity_src);
1416 self->priv->inactivity_src = g_timeout_add_seconds (3,
1417 empathy_call_window_toolbar_timeout, self);
1423 empathy_call_window_configure_event_cb (GtkWidget *widget,
1425 EmpathyCallWindow *self)
1427 GdkWindow *gdk_window;
1428 GdkWindowState window_state;
1430 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1431 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1433 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1434 &self->priv->dialpad_width, NULL);
1436 gdk_window = gtk_widget_get_window (widget);
1437 window_state = gdk_window_get_state (gdk_window);
1438 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1444 empathy_call_window_destroyed_cb (GtkWidget *object,
1445 EmpathyCallWindow *self)
1447 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1449 /* Save the geometry as if the dialpad was hidden. */
1450 empathy_geometry_save_values (GTK_WINDOW (self),
1451 self->priv->x, self->priv->y,
1452 self->priv->w - self->priv->dialpad_width, self->priv->h,
1453 self->priv->maximized);
1458 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1460 EmpathyCallWindow *self)
1462 switch (response_id)
1464 case GTK_RESPONSE_ACCEPT:
1465 tp_channel_dispatch_operation_handle_with_async (
1466 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1468 tp_clear_object (&self->priv->pending_cdo);
1469 tp_clear_object (&self->priv->pending_channel);
1470 tp_clear_object (&self->priv->pending_context);
1473 case GTK_RESPONSE_CANCEL:
1474 tp_channel_dispatch_operation_close_channels_async (
1475 self->priv->pending_cdo, NULL, NULL);
1477 empathy_call_window_status_message (self, _("Disconnected"));
1478 self->priv->call_state = DISCONNECTED;
1481 g_warn_if_reached ();
1486 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1490 g_assert (self->priv->call_state != CONNECTED);
1492 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1494 empathy_call_window_status_message (self, _("Incoming call"));
1495 self->priv->call_state = RINGING;
1497 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1498 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1499 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1500 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1501 empathy_contact_get_alias (self->priv->contact));
1503 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1504 _("Reject"), GTK_RESPONSE_CANCEL,
1505 _("Answer"), GTK_RESPONSE_ACCEPT,
1508 g_signal_connect (self->priv->incoming_call_dialog, "response",
1509 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1510 gtk_widget_show (self->priv->incoming_call_dialog);
1514 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1518 EmpathyCallWindow *self)
1520 tp_clear_object (&self->priv->pending_cdo);
1521 tp_clear_object (&self->priv->pending_channel);
1522 tp_clear_object (&self->priv->pending_context);
1524 /* We don't know if the incoming call has been accepted or not, so we
1525 * assume it hasn't and if it has, we'll set the proper status when
1526 * we get the new handler. */
1527 empathy_call_window_status_message (self, _("Disconnected"));
1528 self->priv->call_state = DISCONNECTED;
1530 gtk_widget_destroy (self->priv->incoming_call_dialog);
1531 self->priv->incoming_call_dialog = NULL;
1535 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1536 TpCallChannel *channel,
1537 TpChannelDispatchOperation *dispatch_operation,
1538 TpAddDispatchOperationContext *context)
1540 g_assert (self->priv->pending_channel == NULL);
1541 g_assert (self->priv->pending_context == NULL);
1542 g_assert (self->priv->pending_cdo == NULL);
1544 /* Start ringing and delay until the user answers or hangs. */
1545 self->priv->pending_channel = g_object_ref (channel);
1546 self->priv->pending_context = g_object_ref (context);
1547 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1549 g_signal_connect (self->priv->pending_cdo, "invalidated",
1550 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1552 empathy_call_window_set_state_ringing (self);
1553 tp_add_dispatch_operation_context_accept (context);
1557 empathy_call_window_init (EmpathyCallWindow *self)
1559 EmpathyCallWindowPriv *priv;
1561 GtkWidget *top_vbox;
1563 ClutterConstraint *constraint;
1564 ClutterActor *remote_avatar;
1565 GtkStyleContext *context;
1566 GtkCssProvider *provider;
1570 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1571 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1573 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1575 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1576 gui = empathy_builder_get_file (filename,
1577 "call_window_vbox", &top_vbox,
1578 "errors_vbox", &priv->errors_vbox,
1579 "pane", &priv->pane,
1580 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1581 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1582 "status_label", &priv->status_label,
1583 "audiocall", &priv->audio_call_button,
1584 "videocall", &priv->video_call_button,
1585 "microphone", &priv->mic_button,
1586 "volume", &priv->volume_button,
1587 "camera", &priv->camera_button,
1588 "hangup", &priv->hangup_button,
1589 "dialpad", &priv->dialpad_button,
1590 "toolbar", &priv->toolbar,
1591 "bottom_toolbar", &priv->bottom_toolbar,
1592 "ui_manager", &priv->ui_manager,
1593 "menufullscreen", &priv->menu_fullscreen,
1594 "menupreviewswap", &priv->menu_swap_camera,
1595 "details_vbox", &priv->details_vbox,
1596 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1597 "acodec_encoding_label", &priv->acodec_encoding_label,
1598 "acodec_decoding_label", &priv->acodec_decoding_label,
1599 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1600 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1601 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1602 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1603 "video_local_candidate_label", &priv->video_local_candidate_label,
1604 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1605 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1606 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1607 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1611 empathy_builder_connect (gui, self,
1612 "hangup", "clicked", empathy_call_window_hangup_cb,
1613 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1614 "videocall", "clicked", empathy_call_window_video_call_cb,
1615 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1616 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1617 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1618 "menusettings", "activate", empathy_call_window_settings_cb,
1619 "menucontents", "activate", empathy_call_window_contents_cb,
1620 "menudebug", "activate", empathy_call_window_debug_cb,
1621 "menuabout", "activate", empathy_call_window_about_cb,
1622 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1623 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1624 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1625 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1628 /* FIXME: we should use a stock "OSD" style class for the toolbar,
1629 * once it's available in GTK+/Adwaita.
1631 provider = gtk_css_provider_new ();
1632 gtk_css_provider_load_from_data (provider,
1633 "#CallFloatingToolbar { border-radius: 6px; }", -1, NULL);
1634 gtk_style_context_add_provider (
1635 gtk_widget_get_style_context (priv->bottom_toolbar),
1636 GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1637 g_object_unref (provider);
1639 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1641 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1643 g_object_bind_property (priv->camera_monitor, "available",
1644 priv->camera_button, "sensitive",
1645 G_BINDING_SYNC_CREATE);
1647 g_signal_connect (priv->camera_monitor, "added",
1648 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1649 g_signal_connect (priv->camera_monitor, "removed",
1650 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1652 priv->lock = g_mutex_new ();
1654 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1656 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1657 CONTENT_HBOX_SPACING);
1658 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1659 CONTENT_HBOX_BORDER_WIDTH);
1660 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1663 /* main contents remote avatar/video box */
1664 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1665 CLUTTER_BIN_ALIGNMENT_CENTER);
1667 priv->video_box = clutter_box_new (priv->video_layout);
1669 priv->video_container = gtk_clutter_embed_new ();
1671 gtk_widget_set_size_request (priv->video_container,
1672 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1674 /* Set the background color to that of the rest of the window */
1675 context = gtk_widget_get_style_context (priv->content_hbox);
1676 gtk_style_context_get_background_color (context,
1677 GTK_STATE_FLAG_NORMAL, &rgba);
1678 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1679 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1680 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1681 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1682 clutter_stage_set_color (
1683 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1684 GTK_CLUTTER_EMBED (priv->video_container))),
1687 clutter_container_add (
1688 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1689 GTK_CLUTTER_EMBED (priv->video_container))),
1693 constraint = clutter_bind_constraint_new (
1694 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1695 CLUTTER_BIND_SIZE, 0);
1696 clutter_actor_add_constraint (priv->video_box, constraint);
1698 priv->remote_user_avatar_widget = gtk_image_new ();
1699 remote_avatar = gtk_clutter_actor_new_with_contents (
1700 priv->remote_user_avatar_widget);
1702 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1705 /* create the overlay box */
1706 priv->overlay_layout = clutter_box_layout_new ();
1707 clutter_box_layout_set_vertical (
1708 CLUTTER_BOX_LAYOUT (priv->overlay_layout), TRUE);
1709 priv->overlay_box = clutter_box_new (priv->overlay_layout);
1711 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1713 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1715 empathy_call_window_create_preview_rectangles (self);
1717 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1718 priv->video_container, TRUE, TRUE,
1719 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1721 create_pipeline (self);
1722 create_video_output_widget (self);
1723 create_audio_input (self);
1724 create_video_input (self);
1726 priv->floating_toolbar = gtk_clutter_actor_new ();
1727 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1729 gtk_widget_reparent (priv->bottom_toolbar,
1730 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1732 clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (priv->overlay_layout),
1733 priv->floating_toolbar, FALSE, FALSE, FALSE,
1734 CLUTTER_BOX_ALIGNMENT_CENTER, CLUTTER_BOX_ALIGNMENT_END);
1736 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1738 clutter_actor_raise_top (priv->floating_toolbar);
1740 /* Transitions for the floating toolbar */
1741 priv->transitions = clutter_state_new ();
1743 /* all transitions last for 2s */
1744 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1746 /* transition from any state to "fade-out" state */
1747 clutter_state_set (priv->transitions, NULL, "fade-out",
1748 priv->floating_toolbar,
1749 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1752 /* transition from any state to "fade-in" state */
1753 clutter_state_set (priv->transitions, NULL, "fade-in",
1754 priv->floating_toolbar,
1755 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1758 /* put the actor into the "fade-in" state with no animation */
1759 clutter_state_warp_to_state (priv->transitions, "fade-in");
1761 /* The call will be started as soon the pipeline is playing */
1762 priv->start_call_when_playing = TRUE;
1764 priv->dtmf_panel = empathy_dialpad_widget_new ();
1765 g_signal_connect (priv->dtmf_panel, "start-tone",
1766 G_CALLBACK (dtmf_start_tone_cb), self);
1768 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1771 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1774 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1776 gtk_widget_show_all (top_vbox);
1778 gtk_widget_hide (priv->dtmf_panel);
1779 gtk_widget_hide (priv->details_vbox);
1781 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1783 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1784 priv->video_container);
1786 /* We hide the bottom toolbar after 3s of inactivity and show it
1787 * again on mouse movement */
1788 priv->inactivity_src = g_timeout_add_seconds (3,
1789 empathy_call_window_toolbar_timeout, self);
1791 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1792 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1794 g_signal_connect (G_OBJECT (self), "realize",
1795 G_CALLBACK (empathy_call_window_realized_cb), self);
1797 g_signal_connect (G_OBJECT (self), "delete-event",
1798 G_CALLBACK (empathy_call_window_delete_cb), self);
1800 g_signal_connect (G_OBJECT (self), "window-state-event",
1801 G_CALLBACK (empathy_call_window_state_event_cb), self);
1803 g_signal_connect (G_OBJECT (self), "key-press-event",
1804 G_CALLBACK (empathy_call_window_key_press_cb), self);
1806 g_signal_connect (self, "motion-notify-event",
1807 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1809 priv->timer = g_timer_new ();
1811 g_object_ref (priv->ui_manager);
1812 g_object_unref (gui);
1814 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1815 priv->mic_menu = empathy_mic_menu_new (self);
1816 priv->camera_menu = empathy_camera_menu_new (self);
1818 empathy_call_window_show_hangup_button (self, TRUE);
1820 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1821 /* These signals are used to track the window position and save it
1822 * when the window is destroyed. We need to do this as we don't want
1823 * the window geometry to be saved with the dialpad taken into account. */
1824 g_signal_connect (self, "destroy",
1825 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1826 g_signal_connect (self, "configure-event",
1827 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1828 g_signal_connect (self, "window-state-event",
1829 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1831 /* Don't display labels in both toolbars */
1832 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1835 /* Instead of specifying a width and a height, we specify only one size. That's
1836 because we want a square avatar icon. */
1838 init_contact_avatar_with_size (EmpathyContact *contact,
1839 GtkWidget *image_widget,
1842 GdkPixbuf *pixbuf_avatar = NULL;
1844 if (contact != NULL)
1846 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1850 if (pixbuf_avatar == NULL)
1852 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1853 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1856 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1858 if (pixbuf_avatar != NULL)
1859 g_object_unref (pixbuf_avatar);
1863 set_window_title (EmpathyCallWindow *self)
1865 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1868 if (priv->contact != NULL)
1870 /* translators: Call is a noun and %s is the contact name. This string
1871 * is used in the window title */
1872 tmp = g_strdup_printf (_("Call with %s"),
1873 empathy_contact_get_alias (priv->contact));
1874 gtk_window_set_title (GTK_WINDOW (self), tmp);
1879 g_warning ("Unknown remote contact!");
1884 set_remote_user_name (EmpathyCallWindow *self,
1885 EmpathyContact *contact)
1887 const gchar *alias = empathy_contact_get_alias (contact);
1888 const gchar *status = empathy_contact_get_status (contact);
1891 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1892 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1898 contact_name_changed_cb (EmpathyContact *contact,
1900 EmpathyCallWindow *self)
1902 set_window_title (self);
1903 set_remote_user_name (self, contact);
1907 contact_presence_changed_cb (EmpathyContact *contact,
1909 EmpathyCallWindow *self)
1911 set_remote_user_name (self, contact);
1915 contact_avatar_changed_cb (EmpathyContact *contact,
1917 EmpathyCallWindow *self)
1920 GtkAllocation allocation;
1921 GtkWidget *avatar_widget;
1923 avatar_widget = self->priv->remote_user_avatar_widget;
1925 gtk_widget_get_allocation (avatar_widget, &allocation);
1926 size = allocation.height;
1930 /* the widget is not allocated yet, set a default size */
1931 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1932 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1935 init_contact_avatar_with_size (contact, avatar_widget, size);
1937 avatar_widget = self->priv->remote_user_avatar_toolbar;
1939 gtk_widget_get_allocation (avatar_widget, &allocation);
1940 size = allocation.height;
1944 /* the widget is not allocated yet, set a default size */
1945 size = SMALL_TOOLBAR_SIZE;
1948 init_contact_avatar_with_size (contact, avatar_widget, size);
1952 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1953 EmpathyCallHandler *handler)
1955 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1957 tp_g_signal_connect_object (priv->contact, "notify::name",
1958 G_CALLBACK (contact_name_changed_cb), self, 0);
1959 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1960 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1961 tp_g_signal_connect_object (priv->contact, "notify::presence",
1962 G_CALLBACK (contact_presence_changed_cb), self, 0);
1964 set_window_title (self);
1965 set_remote_user_name (self, priv->contact);
1967 init_contact_avatar_with_size (priv->contact,
1968 priv->remote_user_avatar_widget,
1969 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1970 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1972 init_contact_avatar_with_size (priv->contact,
1973 priv->remote_user_avatar_toolbar,
1974 SMALL_TOOLBAR_SIZE);
1976 /* The remote avatar is shown by default and will be hidden when we receive
1977 video from the remote side. */
1978 clutter_actor_hide (priv->video_output);
1979 gtk_widget_show (priv->remote_user_avatar_widget);
1983 update_send_codec (EmpathyCallWindow *self,
1986 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1993 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1994 widget = priv->acodec_encoding_label;
1998 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1999 widget = priv->vcodec_encoding_label;
2005 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2006 gtk_label_set_text (GTK_LABEL (widget), tmp);
2011 send_audio_codec_notify_cb (GObject *object,
2015 EmpathyCallWindow *self = user_data;
2017 update_send_codec (self, TRUE);
2021 send_video_codec_notify_cb (GObject *object,
2025 EmpathyCallWindow *self = user_data;
2027 update_send_codec (self, FALSE);
2031 update_recv_codec (EmpathyCallWindow *self,
2034 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2037 GString *str = NULL;
2041 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2042 widget = priv->acodec_decoding_label;
2046 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2047 widget = priv->vcodec_decoding_label;
2053 for (l = codecs; l != NULL; l = g_list_next (l))
2055 FsCodec *codec = l->data;
2058 str = g_string_new (NULL);
2060 g_string_append (str, ", ");
2062 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2066 gtk_label_set_text (GTK_LABEL (widget), str->str);
2067 g_string_free (str, TRUE);
2071 recv_audio_codecs_notify_cb (GObject *object,
2075 EmpathyCallWindow *self = user_data;
2077 update_recv_codec (self, TRUE);
2081 recv_video_codecs_notify_cb (GObject *object,
2085 EmpathyCallWindow *self = user_data;
2087 update_recv_codec (self, FALSE);
2090 static const gchar *
2091 candidate_type_to_str (FsCandidate *candidate)
2093 switch (candidate->type)
2095 case FS_CANDIDATE_TYPE_HOST:
2097 case FS_CANDIDATE_TYPE_SRFLX:
2098 return "server reflexive";
2099 case FS_CANDIDATE_TYPE_PRFLX:
2100 return "peer reflexive";
2101 case FS_CANDIDATE_TYPE_RELAY:
2103 case FS_CANDIDATE_TYPE_MULTICAST:
2110 static const gchar *
2111 candidate_type_to_desc (FsCandidate *candidate)
2113 switch (candidate->type)
2115 case FS_CANDIDATE_TYPE_HOST:
2116 return _("The IP address as seen by the machine");
2117 case FS_CANDIDATE_TYPE_SRFLX:
2118 return _("The IP address as seen by a server on the Internet");
2119 case FS_CANDIDATE_TYPE_PRFLX:
2120 return _("The IP address of the peer as seen by the other side");
2121 case FS_CANDIDATE_TYPE_RELAY:
2122 return _("The IP address of a relay server");
2123 case FS_CANDIDATE_TYPE_MULTICAST:
2124 return _("The IP address of the multicast group");
2131 update_candidat_widget (EmpathyCallWindow *self,
2134 FsCandidate *candidate)
2138 g_assert (candidate != NULL);
2139 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2140 candidate->port, candidate_type_to_str (candidate));
2142 gtk_label_set_text (GTK_LABEL (label), str);
2143 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2149 candidates_changed_cb (GObject *object,
2151 EmpathyCallWindow *self)
2153 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2154 FsCandidate *candidate = NULL;
2156 if (type == FS_MEDIA_TYPE_VIDEO)
2158 /* Update remote candidate */
2159 candidate = empathy_call_handler_get_video_remote_candidate (
2162 update_candidat_widget (self, priv->video_remote_candidate_label,
2163 priv->video_remote_candidate_info_img, candidate);
2165 /* Update local candidate */
2166 candidate = empathy_call_handler_get_video_local_candidate (
2169 update_candidat_widget (self, priv->video_local_candidate_label,
2170 priv->video_local_candidate_info_img, candidate);
2174 /* Update remote candidate */
2175 candidate = empathy_call_handler_get_audio_remote_candidate (
2178 update_candidat_widget (self, priv->audio_remote_candidate_label,
2179 priv->audio_remote_candidate_info_img, candidate);
2181 /* Update local candidate */
2182 candidate = empathy_call_handler_get_audio_local_candidate (
2185 update_candidat_widget (self, priv->audio_local_candidate_label,
2186 priv->audio_local_candidate_info_img, candidate);
2191 empathy_call_window_constructed (GObject *object)
2193 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2194 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2195 TpCallChannel *call;
2198 g_assert (priv->handler != NULL);
2200 g_object_get (priv->handler, "call-channel", &call, NULL);
2201 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2202 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2203 tp_clear_object (&call);
2205 priv->contact = empathy_call_handler_get_contact (priv->handler);
2206 g_assert (priv->contact != NULL);
2207 g_object_ref (priv->contact);
2209 if (!empathy_contact_can_voip_video (priv->contact))
2211 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2212 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2215 empathy_call_window_setup_avatars (self, priv->handler);
2216 empathy_call_window_set_state_connecting (self);
2218 if (!empathy_call_handler_has_initial_video (priv->handler))
2220 gtk_toggle_tool_button_set_active (
2221 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2223 /* If call has InitialVideo, the preview will be started once the call has
2224 * been started (start_call()). */
2226 update_send_codec (self, TRUE);
2227 update_send_codec (self, FALSE);
2228 update_recv_codec (self, TRUE);
2229 update_recv_codec (self, FALSE);
2231 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2232 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2233 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2234 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2235 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2236 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2237 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2238 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2240 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2241 G_CALLBACK (candidates_changed_cb), self, 0);
2244 static void empathy_call_window_dispose (GObject *object);
2245 static void empathy_call_window_finalize (GObject *object);
2248 empathy_call_window_set_property (GObject *object,
2249 guint property_id, const GValue *value, GParamSpec *pspec)
2251 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2253 switch (property_id)
2255 case PROP_CALL_HANDLER:
2256 priv->handler = g_value_dup_object (value);
2259 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2264 empathy_call_window_get_property (GObject *object,
2265 guint property_id, GValue *value, GParamSpec *pspec)
2267 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2269 switch (property_id)
2271 case PROP_CALL_HANDLER:
2272 g_value_set_object (value, priv->handler);
2275 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2280 empathy_call_window_class_init (
2281 EmpathyCallWindowClass *empathy_call_window_class)
2283 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2284 GParamSpec *param_spec;
2286 g_type_class_add_private (empathy_call_window_class,
2287 sizeof (EmpathyCallWindowPriv));
2289 object_class->constructed = empathy_call_window_constructed;
2290 object_class->set_property = empathy_call_window_set_property;
2291 object_class->get_property = empathy_call_window_get_property;
2293 object_class->dispose = empathy_call_window_dispose;
2294 object_class->finalize = empathy_call_window_finalize;
2296 param_spec = g_param_spec_object ("handler",
2297 "handler", "The call handler",
2298 EMPATHY_TYPE_CALL_HANDLER,
2299 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2300 g_object_class_install_property (object_class,
2301 PROP_CALL_HANDLER, param_spec);
2305 empathy_call_window_dispose (GObject *object)
2307 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2308 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2310 if (priv->dispose_has_run)
2313 priv->dispose_has_run = TRUE;
2315 if (priv->handler != NULL)
2317 empathy_call_handler_stop_call (priv->handler);
2318 tp_clear_object (&priv->handler);
2321 if (priv->bus_message_source_id != 0)
2323 g_source_remove (priv->bus_message_source_id);
2324 priv->bus_message_source_id = 0;
2327 if (priv->got_video_src > 0)
2329 g_source_remove (priv->got_video_src);
2330 priv->got_video_src = 0;
2333 if (priv->inactivity_src > 0)
2335 g_source_remove (priv->inactivity_src);
2336 priv->inactivity_src = 0;
2339 tp_clear_object (&priv->pipeline);
2340 tp_clear_object (&priv->video_input);
2341 tp_clear_object (&priv->audio_input);
2342 tp_clear_object (&priv->video_tee);
2343 tp_clear_object (&priv->ui_manager);
2344 tp_clear_object (&priv->fullscreen);
2345 tp_clear_object (&priv->camera_monitor);
2346 tp_clear_object (&priv->settings);
2347 tp_clear_object (&priv->sound_mgr);
2348 tp_clear_object (&priv->mic_menu);
2349 tp_clear_object (&priv->camera_menu);
2350 tp_clear_object (&priv->transitions);
2352 g_list_free_full (priv->notifiers, g_object_unref);
2354 if (priv->timer_id != 0)
2355 g_source_remove (priv->timer_id);
2358 tp_clear_object (&priv->contact);
2360 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2364 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2366 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2368 if (priv->video_output_motion_handler_id != 0)
2370 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2371 priv->video_output_motion_handler_id);
2372 priv->video_output_motion_handler_id = 0;
2377 empathy_call_window_finalize (GObject *object)
2379 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2380 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2382 disconnect_video_output_motion_handler (self);
2384 /* free any data held directly by the object here */
2385 g_mutex_free (priv->lock);
2387 g_timer_destroy (priv->timer);
2389 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2394 empathy_call_window_new (EmpathyCallHandler *handler)
2396 return EMPATHY_CALL_WINDOW (
2397 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2401 empathy_call_window_present (EmpathyCallWindow *self,
2402 EmpathyCallHandler *handler)
2404 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2406 empathy_window_present (GTK_WINDOW (self));
2408 if (self->priv->call_state == DISCONNECTED)
2410 /* start a new call if one is not already in progress */
2411 tp_clear_object (&self->priv->handler);
2412 self->priv->handler = g_object_ref (handler);
2413 empathy_call_window_connect_handler (self);
2415 empathy_call_window_restart_call (self);
2420 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2421 GstElement *conference, gpointer user_data)
2423 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2424 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2425 FsElementAddedNotifier *notifier;
2428 DEBUG ("Conference added");
2430 /* Add notifier to set the various element properties as needed */
2431 notifier = fs_element_added_notifier_new ();
2432 keyfile = fs_utils_get_default_element_properties (conference);
2434 if (keyfile != NULL)
2435 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2437 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2439 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2441 gst_bin_add (GST_BIN (priv->pipeline), conference);
2442 gst_element_set_state (conference, GST_STATE_PLAYING);
2446 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2447 GstElement *conference, gpointer user_data)
2449 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2450 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2452 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2453 gst_element_set_state (conference, GST_STATE_NULL);
2457 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2459 GstStateChangeReturn state_change_return;
2460 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2462 if (priv->pipeline == NULL)
2465 if (priv->bus_message_source_id != 0)
2467 g_source_remove (priv->bus_message_source_id);
2468 priv->bus_message_source_id = 0;
2471 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2473 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2474 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2476 if (priv->pipeline != NULL)
2477 g_object_unref (priv->pipeline);
2478 priv->pipeline = NULL;
2480 if (priv->audio_output != NULL)
2481 g_object_unref (priv->audio_output);
2482 priv->audio_output = NULL;
2483 priv->audio_output_added = FALSE;
2485 if (priv->video_tee != NULL)
2486 g_object_unref (priv->video_tee);
2487 priv->video_tee = NULL;
2489 if (priv->video_preview != NULL)
2490 clutter_actor_destroy (priv->video_preview);
2491 priv->video_preview = NULL;
2493 /* If we destroy the preview while it's being dragged, we won't
2494 * get the ::drag-end signal, so manually destroy the clone */
2495 if (priv->drag_preview != NULL)
2497 clutter_actor_destroy (priv->drag_preview);
2498 empathy_call_window_show_preview_rectangles (self, FALSE);
2499 priv->drag_preview = NULL;
2502 priv->funnel = NULL;
2504 create_pipeline (self);
2505 /* Call will be started when user will hit the 'redial' button */
2506 priv->start_call_when_playing = FALSE;
2507 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2513 g_message ("Error: could not destroy pipeline. Closing call window");
2514 gtk_widget_destroy (GTK_WIDGET (self));
2521 reset_details_pane (EmpathyCallWindow *self)
2523 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2525 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2526 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2527 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2528 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2532 empathy_call_window_disconnected (EmpathyCallWindow *self,
2535 gboolean could_disconnect = FALSE;
2536 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2537 gboolean could_reset_pipeline;
2539 /* Leave full screen mode if needed */
2540 gtk_window_unfullscreen (GTK_WINDOW (self));
2542 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2543 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2545 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2547 if (priv->call_state == CONNECTING)
2548 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2550 if (priv->call_state != REDIALING)
2551 priv->call_state = DISCONNECTED;
2553 /* Show the toolbar */
2554 clutter_state_set_state (priv->transitions, "fade-in");
2556 if (could_reset_pipeline)
2558 g_mutex_lock (priv->lock);
2560 g_timer_stop (priv->timer);
2562 if (priv->timer_id != 0)
2563 g_source_remove (priv->timer_id);
2566 g_mutex_unlock (priv->lock);
2569 /* We are about to destroy the window, no need to update it or create
2570 * a video preview */
2573 empathy_call_window_status_message (self, _("Disconnected"));
2575 empathy_call_window_show_hangup_button (self, FALSE);
2577 /* Unsensitive the camera and mic button */
2578 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2579 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2581 /* Be sure that the mic button is enabled */
2582 gtk_toggle_tool_button_set_active (
2583 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2585 if (priv->camera_state == CAMERA_STATE_ON)
2587 /* Restart the preview with the new pipeline. */
2588 display_video_preview (self, TRUE);
2591 /* destroy the video output; it will be recreated when we'll redial */
2592 disconnect_video_output_motion_handler (self);
2593 if (priv->video_output != NULL)
2594 clutter_actor_destroy (priv->video_output);
2595 priv->video_output = NULL;
2596 if (priv->got_video_src > 0)
2598 g_source_remove (priv->got_video_src);
2599 priv->got_video_src = 0;
2602 gtk_widget_show (priv->remote_user_avatar_widget);
2604 reset_details_pane (self);
2606 priv->sending_video = FALSE;
2607 priv->call_started = FALSE;
2609 could_disconnect = TRUE;
2611 /* TODO: display the self avatar of the preview (depends if the "Always
2612 * Show Video Preview" is enabled or not) */
2615 return could_disconnect;
2620 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2623 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2624 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2626 if (empathy_call_window_disconnected (self, TRUE) &&
2627 priv->call_state == REDIALING)
2628 empathy_call_window_restart_call (self);
2632 empathy_call_window_content_is_raw (TfContent *content)
2634 FsConference *conference;
2637 g_object_get (content, "fs-conference", &conference, NULL);
2638 g_assert (conference != NULL);
2640 /* FIXME: Ugly hack, update when moving a packetization property into
2642 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2643 gst_object_unref (conference);
2649 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2651 EmpathyCallWindow *self)
2653 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2654 FsMediaType media_type;
2656 DEBUG ("removing content");
2658 g_object_get (content, "media-type", &media_type, NULL);
2661 * This assumes that there is only one video stream per channel...
2664 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2666 if (priv->funnel != NULL)
2670 output = priv->video_output_sink;
2672 gst_element_set_state (output, GST_STATE_NULL);
2673 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2675 gst_bin_remove (GST_BIN (priv->pipeline), output);
2676 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2677 priv->funnel = NULL;
2680 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2682 if (priv->audio_output != NULL)
2684 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2686 if (priv->audio_output_added)
2687 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2688 priv->audio_output = NULL;
2689 priv->audio_output_added = FALSE;
2694 g_assert_not_reached ();
2701 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2703 EmpathyCallWindow *self)
2705 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2707 DEBUG ("Framerate changed to %u", framerate);
2709 if (priv->video_input != NULL)
2710 empathy_video_src_set_framerate (priv->video_input, framerate);
2714 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2717 EmpathyCallWindow *self)
2719 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2721 DEBUG ("Resolution changed to %ux%u", width, height);
2723 if (priv->video_input != NULL)
2725 empathy_video_src_set_resolution (priv->video_input, width, height);
2729 /* Called with global lock held */
2731 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2733 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2737 if (priv->funnel == NULL)
2739 output = priv->video_output_sink;
2741 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2745 g_warning ("Could not create fsfunnel");
2749 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2751 gst_object_unref (priv->funnel);
2752 priv->funnel = NULL;
2753 g_warning ("Could not add funnel to pipeline");
2757 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2759 g_warning ("Could not add the video output widget to the pipeline");
2763 if (!gst_element_link (priv->funnel, output))
2765 g_warning ("Could not link output sink to funnel");
2766 goto error_output_added;
2769 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2771 g_warning ("Could not start video sink");
2772 goto error_output_added;
2775 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2777 g_warning ("Could not start funnel");
2778 goto error_output_added;
2782 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2785 g_warning ("Could not get request pad from funnel");
2792 gst_element_set_locked_state (priv->funnel, TRUE);
2793 gst_element_set_locked_state (output, TRUE);
2795 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2796 gst_element_set_state (output, GST_STATE_NULL);
2798 gst_bin_remove (GST_BIN (priv->pipeline), output);
2799 gst_element_set_locked_state (output, FALSE);
2803 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2804 priv->funnel = NULL;
2809 /* Called with global lock held */
2811 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2814 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2816 GstPadTemplate *template;
2818 if (!priv->audio_output_added)
2820 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2822 g_warning ("Could not add audio sink to pipeline");
2823 g_object_unref (priv->audio_output);
2824 goto error_add_output;
2827 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2829 g_warning ("Could not start audio sink");
2834 template = gst_element_class_get_pad_template (
2835 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2837 pad = gst_element_request_pad (priv->audio_output,
2838 template, NULL, NULL);
2842 g_warning ("Could not get sink pad from sink");
2849 gst_element_set_locked_state (priv->audio_output, TRUE);
2850 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2851 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2852 priv->audio_output = NULL;
2860 empathy_call_window_update_timer (gpointer user_data)
2862 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2863 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2864 const gchar *status;
2868 time_ = g_timer_elapsed (priv->timer, NULL);
2870 if (priv->call_state == HELD)
2871 status = _("On hold");
2872 else if (!gtk_toggle_tool_button_get_active (
2873 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2876 status = _("Duration");
2878 /* Translators: 'status - minutes:seconds' the caller has been connected */
2879 str = g_strdup_printf (_("%s — %d:%02dm"),
2881 (int) time_ / 60, (int) time_ % 60);
2882 empathy_call_window_status_message (self, str);
2890 EMP_RESPONSE_BALANCE
2894 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2898 switch (response_id)
2900 case GTK_RESPONSE_CLOSE:
2901 gtk_widget_destroy (GTK_WIDGET (info_bar));
2903 case EMP_RESPONSE_BALANCE:
2904 empathy_url_show (GTK_WIDGET (info_bar),
2905 g_object_get_data (G_OBJECT (info_bar), "uri"));
2911 display_error (EmpathyCallWindow *self,
2915 const gchar *details,
2916 const gchar *button_text,
2918 gint button_response)
2920 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2921 GtkWidget *info_bar;
2922 GtkWidget *content_area;
2929 /* Create info bar */
2930 info_bar = gtk_info_bar_new ();
2932 if (button_text != NULL)
2934 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2935 button_text, button_response);
2936 g_object_set_data_full (G_OBJECT (info_bar),
2937 "uri", g_strdup (uri), g_free);
2940 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2941 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
2943 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2945 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2947 /* hbox containing the image and the messages vbox */
2948 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2949 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2952 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2953 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2955 /* vbox containing the main message and the details expander */
2956 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2957 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2960 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2962 label = gtk_label_new (NULL);
2963 gtk_label_set_markup (GTK_LABEL (label), txt);
2964 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2965 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2968 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2971 if (details != NULL)
2973 GtkWidget *expander;
2975 expander = gtk_expander_new (_("Technical Details"));
2977 txt = g_strdup_printf ("<i>%s</i>", details);
2979 label = gtk_label_new (NULL);
2980 gtk_label_set_markup (GTK_LABEL (label), txt);
2981 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2982 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2985 gtk_container_add (GTK_CONTAINER (expander), label);
2986 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2989 g_signal_connect (info_bar, "response",
2990 G_CALLBACK (on_error_infobar_response_cb), NULL);
2992 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2993 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2994 gtk_widget_show_all (info_bar);
2999 media_stream_error_to_txt (EmpathyCallWindow *self,
3000 TpCallChannel *call,
3002 TpMediaStreamError error)
3004 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3005 const gchar *cm = NULL;
3011 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3013 return g_strdup_printf (
3014 _("%s's software does not understand any of the audio formats "
3015 "supported by your computer"),
3016 empathy_contact_get_alias (priv->contact));
3018 return g_strdup_printf (
3019 _("%s's software does not understand any of the video formats "
3020 "supported by your computer"),
3021 empathy_contact_get_alias (priv->contact));
3023 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3024 return g_strdup_printf (
3025 _("Can't establish a connection to %s. "
3026 "One of you might be on a network that does not allow "
3027 "direct connections."),
3028 empathy_contact_get_alias (priv->contact));
3030 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3031 return g_strdup (_("There was a failure on the network"));
3033 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3035 return g_strdup (_("The audio formats necessary for this call "
3036 "are not installed on your computer"));
3038 return g_strdup (_("The video formats necessary for this call "
3039 "are not installed on your computer"));
3041 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3042 tp_connection_parse_object_path (
3043 tp_channel_borrow_connection (TP_CHANNEL (call)),
3046 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3047 "product=Telepathy&component=%s", cm);
3049 result = g_strdup_printf (
3050 _("Something unexpected happened in a Telepathy component. "
3051 "Please <a href=\"%s\">report this bug</a> and attach "
3052 "logs gathered from the 'Debug' window in the Help menu."), url);
3058 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3059 return g_strdup (_("There was a failure in the call engine"));
3061 case TP_MEDIA_STREAM_ERROR_EOS:
3062 return g_strdup (_("The end of the stream was reached"));
3064 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3071 empathy_call_window_stream_error (EmpathyCallWindow *self,
3072 TpCallChannel *call,
3081 desc = media_stream_error_to_txt (self, call, audio, code);
3084 /* No description, use the error message. That's not great as it's not
3085 * localized but it's better than nothing. */
3086 display_error (self, call, icon, title, msg, NULL);
3090 display_error (self, call, icon, title, desc, msg);
3096 empathy_call_window_audio_stream_error (TpCallChannel *call,
3099 EmpathyCallWindow *self)
3101 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3102 "gnome-stock-mic", _("Can't establish audio stream"));
3106 empathy_call_window_video_stream_error (TpCallChannel *call,
3109 EmpathyCallWindow *self)
3111 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3112 "camera-web", _("Can't establish video stream"));
3117 show_balance_error (EmpathyCallWindow *self)
3121 gchar *balance, *tmp;
3122 const gchar *uri, *currency;
3126 g_object_get (self->priv->handler,
3127 "call-channel", &call,
3130 conn = tp_channel_borrow_connection (call);
3131 g_object_unref (call);
3133 uri = tp_connection_get_balance_uri (conn);
3135 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3137 /* unknown balance */
3138 balance = g_strdup ("(--)");
3142 char *money = empathy_format_currency (amount, scale, currency);
3144 balance = g_strdup_printf ("%s %s",
3149 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3151 display_error (self,
3153 _("Sorry, you don’t have enough credit for that call."),
3157 EMP_RESPONSE_BALANCE);
3164 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3167 EmpathyCallWindow *self)
3169 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3170 TpCallChannel *call;
3171 gboolean can_send_video;
3173 if (state == TP_CALL_STATE_ENDED)
3175 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3176 empathy_call_window_disconnected (self, TRUE);
3177 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3178 show_balance_error (self);
3182 if (state != TP_CALL_STATE_ACCEPTED)
3185 if (priv->call_state == CONNECTED)
3188 g_timer_start (priv->timer);
3189 priv->call_state = CONNECTED;
3191 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3193 can_send_video = priv->video_input != NULL &&
3194 empathy_contact_can_voip_video (priv->contact) &&
3195 empathy_camera_monitor_get_available (priv->camera_monitor);
3197 g_object_get (priv->handler, "call-channel", &call, NULL);
3199 if (tp_call_channel_has_dtmf (call))
3200 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3202 if (priv->video_input == NULL)
3203 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3205 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3207 empathy_call_window_show_hangup_button (self, TRUE);
3209 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3211 clutter_actor_hide (priv->video_output);
3212 gtk_widget_show (priv->remote_user_avatar_widget);
3214 g_object_unref (call);
3216 g_mutex_lock (priv->lock);
3218 priv->timer_id = g_timeout_add_seconds (1,
3219 empathy_call_window_update_timer, self);
3221 g_mutex_unlock (priv->lock);
3223 empathy_call_window_update_timer (self);
3225 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3229 empathy_call_window_show_video_output_cb (gpointer user_data)
3231 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3233 if (self->priv->video_output != NULL)
3235 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3236 clutter_actor_show (self->priv->video_output);
3237 empathy_call_window_raise_actors (self);
3244 empathy_call_window_check_video_cb (gpointer data)
3246 EmpathyCallWindow *self = data;
3248 if (self->priv->got_video)
3250 self->priv->got_video = FALSE;
3254 /* No video in the last N seconds, display the remote avatar */
3255 empathy_call_window_show_video_output (self, FALSE);
3260 /* Called from the streaming thread */
3262 empathy_call_window_video_probe_cb (GstPad *pad,
3263 GstMiniObject *mini_obj,
3264 EmpathyCallWindow *self)
3267 if (GST_IS_EVENT (mini_obj))
3270 if (G_UNLIKELY (!self->priv->got_video))
3272 /* show the remote video */
3273 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3274 empathy_call_window_show_video_output_cb,
3275 g_object_ref (self), g_object_unref);
3277 self->priv->got_video = TRUE;
3283 /* Called from the streaming thread */
3285 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3286 TfContent *content, GstPad *src, gpointer user_data)
3288 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3289 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3290 gboolean retval = FALSE;
3295 g_mutex_lock (priv->lock);
3297 g_object_get (content, "media-type", &media_type, NULL);
3301 case TP_MEDIA_STREAM_TYPE_AUDIO:
3302 pad = empathy_call_window_get_audio_sink_pad (self, content);
3304 case TP_MEDIA_STREAM_TYPE_VIDEO:
3305 g_idle_add (empathy_call_window_show_video_output_cb, self);
3306 pad = empathy_call_window_get_video_sink_pad (self);
3308 gst_pad_add_data_probe (src,
3309 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3310 if (priv->got_video_src > 0)
3311 g_source_remove (priv->got_video_src);
3312 priv->got_video_src = g_timeout_add_seconds (1,
3313 empathy_call_window_check_video_cb, self);
3316 g_assert_not_reached ();
3322 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3323 g_warning ("Could not link %s sink pad",
3324 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3328 gst_object_unref (pad);
3332 /* If no sink could be linked, try to add fakesink to prevent the whole call
3337 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3339 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3341 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3342 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3343 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3345 gst_element_set_locked_state (fakesink, TRUE);
3346 gst_element_set_state (fakesink, GST_STATE_NULL);
3347 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3351 DEBUG ("Could not link real sink, linked fakesink instead");
3353 gst_object_unref (sinkpad);
3357 gst_object_unref (fakesink);
3362 g_mutex_unlock (priv->lock);
3368 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3371 EmpathyCallWindowPriv *priv = self->priv;
3373 g_assert (priv->audio_output_added == FALSE);
3374 g_assert (priv->audio_output == FALSE);
3376 priv->audio_output = empathy_audio_sink_new ();
3377 g_object_ref_sink (priv->audio_output);
3379 /* volume button to output volume linking */
3380 g_object_bind_property (priv->audio_output, "volume",
3381 priv->volume_button, "value",
3382 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3384 g_object_bind_property_full (content, "requested-output-volume",
3385 priv->audio_output, "volume",
3387 audio_control_volume_to_element,
3388 element_volume_to_audio_control,
3391 /* Link volumes together, sync the current audio input volume property
3392 * back to farstream first */
3393 g_object_bind_property_full (priv->audio_output, "volume",
3394 content, "reported-output-volume",
3395 G_BINDING_SYNC_CREATE,
3396 element_volume_to_audio_control,
3397 audio_control_volume_to_element,
3400 /* For raw audio conferences assume that the producer of the raw data
3401 * has already processed it, so turn off any echo cancellation and any
3402 * other audio improvements that come with it */
3403 empathy_audio_sink_set_echo_cancel (
3404 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3405 !empathy_call_window_content_is_raw (content));
3410 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3411 TfContent *content, gpointer user_data)
3413 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3414 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3416 FsMediaType media_type;
3417 gboolean retval = FALSE;
3419 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3420 g_assert (sink != NULL);
3424 case FS_MEDIA_TYPE_AUDIO:
3426 /* For raw audio conferences assume that the receiver of the raw data
3427 * wants it unprocessed, so turn off any echo cancellation and any
3428 * other audio improvements that come with it */
3429 empathy_audio_src_set_echo_cancel (
3430 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3431 !empathy_call_window_content_is_raw (content));
3433 /* Link volumes together, sync the current audio input volume property
3434 * back to farstream first */
3435 g_object_bind_property_full (content, "requested-input-volume",
3436 priv->audio_input, "volume",
3438 audio_control_volume_to_element,
3439 element_volume_to_audio_control,
3442 g_object_bind_property_full (priv->audio_input, "volume",
3443 content, "reported-input-volume",
3444 G_BINDING_SYNC_CREATE,
3445 element_volume_to_audio_control,
3446 audio_control_volume_to_element,
3449 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3451 g_warning ("Could not add audio source to pipeline");
3455 pad = gst_element_get_static_pad (priv->audio_input, "src");
3458 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3459 g_warning ("Could not get source pad from audio source");
3463 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3465 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3466 gst_object_unref (pad);
3467 g_warning ("Could not link audio source to farsight");
3470 gst_object_unref (pad);
3472 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3474 g_warning ("Could not start audio source");
3475 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3476 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3480 /* Prepare our audio output, not added yet though */
3481 empathy_call_window_prepare_audio_output (self, content);
3485 case FS_MEDIA_TYPE_VIDEO:
3486 if (priv->video_tee != NULL)
3488 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3489 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3491 g_warning ("Could not link video source input pipeline");
3494 gst_object_unref (pad);
3500 g_assert_not_reached ();
3503 gst_object_unref (sink);
3508 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3510 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3511 GstElement *preview;
3513 disable_camera (self);
3515 DEBUG ("remove video input");
3516 preview = priv->video_preview_sink;
3518 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3519 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3520 gst_element_set_state (preview, GST_STATE_NULL);
3522 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3525 g_object_unref (priv->video_input);
3526 priv->video_input = NULL;
3527 g_object_unref (priv->video_tee);
3528 priv->video_tee = NULL;
3529 clutter_actor_destroy (priv->video_preview);
3530 priv->video_preview = NULL;
3532 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3536 start_call (EmpathyCallWindow *self)
3538 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3540 priv->call_started = TRUE;
3541 empathy_call_handler_start_call (priv->handler,
3542 gtk_get_current_event_time ());
3544 if (empathy_call_handler_has_initial_video (priv->handler))
3546 TpCallChannel *call;
3549 g_object_get (priv->handler, "call-channel", &call, NULL);
3550 /* If the call channel isn't set yet we're requesting it, if we're
3551 * requesting it with initial video it should be PENDING_SEND when we get
3554 s = TP_SENDING_STATE_PENDING_SEND;
3556 s = empathy_call_channel_get_video_state (call);
3558 if (s == TP_SENDING_STATE_PENDING_SEND ||
3559 s == TP_SENDING_STATE_SENDING)
3561 /* Enable 'send video' buttons and display the preview */
3562 gtk_toggle_tool_button_set_active (
3563 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3567 gtk_toggle_tool_button_set_active (
3568 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3570 if (priv->video_preview == NULL)
3572 create_video_preview (self);
3573 add_video_preview_to_pipeline (self);
3578 g_object_unref (call);
3583 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3586 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3587 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3588 GstState newstate, pending;
3590 empathy_call_handler_bus_message (priv->handler, bus, message);
3592 switch (GST_MESSAGE_TYPE (message))
3594 case GST_MESSAGE_STATE_CHANGED:
3595 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3597 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3599 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3600 !priv->call_started)
3602 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3603 if (newstate == GST_STATE_PAUSED)
3605 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3606 priv->pipeline_playing = TRUE;
3608 if (priv->start_call_when_playing)
3612 if (priv->video_preview_sink != NULL &&
3613 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3615 gst_message_parse_state_changed (message, NULL, &newstate,
3618 if (newstate == GST_STATE_PLAYING &&
3619 pending == GST_STATE_VOID_PENDING)
3620 empathy_call_window_stop_camera_spinning (self);
3623 case GST_MESSAGE_ERROR:
3625 GError *error = NULL;
3626 GstElement *gst_error;
3630 gst_message_parse_error (message, &error, &debug);
3631 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3633 g_message ("Element error: %s -- %s\n", error->message, debug);
3635 name = gst_element_get_name (gst_error);
3636 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3638 /* Remove the video input and continue */
3639 if (priv->video_input != NULL)
3640 empathy_call_window_remove_video_input (self);
3641 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3645 empathy_call_window_disconnected (self, TRUE);
3648 g_error_free (error);
3651 case GST_MESSAGE_UNKNOWN:
3652 case GST_MESSAGE_EOS:
3653 case GST_MESSAGE_WARNING:
3654 case GST_MESSAGE_INFO:
3655 case GST_MESSAGE_TAG:
3656 case GST_MESSAGE_BUFFERING:
3657 case GST_MESSAGE_STATE_DIRTY:
3658 case GST_MESSAGE_STEP_DONE:
3659 case GST_MESSAGE_CLOCK_PROVIDE:
3660 case GST_MESSAGE_CLOCK_LOST:
3661 case GST_MESSAGE_NEW_CLOCK:
3662 case GST_MESSAGE_STRUCTURE_CHANGE:
3663 case GST_MESSAGE_STREAM_STATUS:
3664 case GST_MESSAGE_APPLICATION:
3665 case GST_MESSAGE_ELEMENT:
3666 case GST_MESSAGE_SEGMENT_START:
3667 case GST_MESSAGE_SEGMENT_DONE:
3668 case GST_MESSAGE_DURATION:
3669 case GST_MESSAGE_ANY:
3678 empathy_call_window_members_changed_cb (TpCallChannel *call,
3679 GHashTable *updates,
3681 TpCallStateReason *reason,
3682 EmpathyCallWindow *self)
3684 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3685 GHashTableIter iter;
3686 gpointer key, value;
3687 gboolean held = FALSE;
3689 g_hash_table_iter_init (&iter, updates);
3690 while (g_hash_table_iter_next (&iter, &key, &value))
3692 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3694 /* This assumes this is a 1-1 call, otherwise one participant
3695 * putting the call on hold wouldn't mean the call is on hold
3703 priv->call_state = HELD;
3704 else if (priv->call_state == HELD)
3705 priv->call_state = CONNECTED;
3709 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3711 EmpathyCallWindow *self)
3713 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3714 TpCallChannel *call;
3716 g_object_get (priv->handler, "call-channel", &call, NULL);
3721 tp_g_signal_connect_object (call, "audio-stream-error",
3722 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3723 tp_g_signal_connect_object (call, "video-stream-error",
3724 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3727 tp_g_signal_connect_object (call, "members-changed",
3728 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3730 g_object_unref (call);
3734 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3736 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3737 TpCallChannel *call;
3739 g_signal_connect (priv->handler, "state-changed",
3740 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3741 g_signal_connect (priv->handler, "conference-added",
3742 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3743 g_signal_connect (priv->handler, "conference-removed",
3744 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3745 g_signal_connect (priv->handler, "closed",
3746 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3747 g_signal_connect (priv->handler, "src-pad-added",
3748 G_CALLBACK (empathy_call_window_src_added_cb), self);
3749 g_signal_connect (priv->handler, "content-added",
3750 G_CALLBACK (empathy_call_window_content_added_cb), self);
3751 g_signal_connect (priv->handler, "content-removed",
3752 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3754 /* We connect to ::call-channel unconditionally since we'll
3755 * get new channels if we hangup and redial or if we reuse the
3757 g_signal_connect (priv->handler, "notify::call-channel",
3758 G_CALLBACK (call_handler_notify_call_cb), self);
3760 g_signal_connect (priv->handler, "framerate-changed",
3761 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3762 g_signal_connect (priv->handler, "resolution-changed",
3763 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3765 g_object_get (priv->handler, "call-channel", &call, NULL);
3768 /* We won't get notify::call-channel for this channel, so
3769 * directly call the callback. */
3770 call_handler_notify_call_cb (priv->handler, NULL, self);
3771 g_object_unref (call);
3776 empathy_call_window_realized_cb (GtkWidget *widget,
3777 EmpathyCallWindow *self)
3781 /* Make the hangup button twice as wide */
3782 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3783 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3785 empathy_call_window_connect_handler (self);
3787 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3791 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3792 EmpathyCallWindow *window)
3794 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3796 if (priv->pipeline != NULL)
3798 if (priv->bus_message_source_id != 0)
3800 g_source_remove (priv->bus_message_source_id);
3801 priv->bus_message_source_id = 0;
3804 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3807 if (priv->call_state == CONNECTING)
3808 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3814 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3817 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3819 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3824 gtk_widget_hide (priv->dtmf_panel);
3825 gtk_widget_hide (menu);
3826 gtk_widget_hide (priv->toolbar);
3830 if (priv->dialpad_was_visible_before_fs)
3831 gtk_widget_show (priv->dtmf_panel);
3833 gtk_widget_show (menu);
3834 gtk_widget_show (priv->toolbar);
3836 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3837 priv->original_height_before_fs);
3842 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3844 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3846 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3847 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3848 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3849 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3851 if (priv->video_output != NULL)
3854 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3855 priv->video_output, TRUE, TRUE,
3856 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3863 empathy_call_window_state_event_cb (GtkWidget *widget,
3864 GdkEventWindowState *event, EmpathyCallWindow *window)
3866 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3868 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3869 gboolean set_fullscreen = event->new_window_state &
3870 GDK_WINDOW_STATE_FULLSCREEN;
3874 gboolean dialpad_was_visible;
3875 GtkAllocation allocation;
3876 gint original_width, original_height;
3878 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3879 original_width = allocation.width;
3880 original_height = allocation.height;
3882 g_object_get (priv->dtmf_panel,
3883 "visible", &dialpad_was_visible,
3886 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3887 priv->original_width_before_fs = original_width;
3888 priv->original_height_before_fs = original_height;
3890 if (priv->video_output_motion_handler_id == 0 &&
3891 priv->video_output != NULL)
3893 priv->video_output_motion_handler_id = g_signal_connect (
3894 G_OBJECT (priv->video_container), "motion-notify-event",
3895 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3901 disconnect_video_output_motion_handler (window);
3904 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3906 show_controls (window, set_fullscreen);
3907 show_borders (window, set_fullscreen);
3908 gtk_action_set_stock_id (priv->menu_fullscreen,
3909 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3910 priv->is_fullscreen = set_fullscreen;
3917 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3920 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3921 int w, h, dialpad_width;
3922 GtkAllocation allocation;
3924 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3925 w = allocation.width;
3926 h = allocation.height;
3928 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3932 gtk_widget_show (priv->dtmf_panel);
3938 gtk_widget_hide (priv->dtmf_panel);
3942 gtk_window_resize (GTK_WINDOW (window), w, h);
3946 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3949 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3950 TpCallChannel *call;
3952 priv->sending_video = (state == CAMERA_STATE_ON);
3954 if (state == CAMERA_STATE_ON)
3956 /* When we start sending video, we want to show the video preview by
3958 display_video_preview (window, TRUE);
3962 display_video_preview (window, FALSE);
3965 if (priv->call_state != CONNECTED)
3968 g_object_get (priv->handler, "call-channel", &call, NULL);
3969 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3970 empathy_call_channel_send_video (call, priv->sending_video);
3971 g_object_unref (call);
3975 empathy_call_window_hangup_cb (gpointer object,
3976 EmpathyCallWindow *self)
3978 /* stopping the call will put it the ENDED state and
3979 * from state_changed_cb we'll reconfigure the window
3981 empathy_call_handler_stop_call (self->priv->handler);
3985 empathy_call_window_restart_call (EmpathyCallWindow *window)
3987 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3989 /* Remove error info bars */
3990 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3991 (GtkCallback) gtk_widget_destroy, NULL);
3993 create_video_output_widget (window);
3994 priv->outgoing = TRUE;
3995 empathy_call_window_set_state_connecting (window);
3997 if (priv->pipeline_playing)
3998 start_call (window);
4000 /* call will be started when the pipeline is ready */
4001 priv->start_call_when_playing = TRUE;
4003 empathy_call_window_setup_avatars (window, priv->handler);
4005 empathy_call_window_show_hangup_button (window, TRUE);
4009 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4010 EmpathyCallWindow *window)
4014 active = gtk_toggle_tool_button_get_active (button);
4016 empathy_call_window_show_dialpad (window, active);
4020 empathy_call_window_fullscreen_cb (gpointer object,
4021 EmpathyCallWindow *window)
4023 empathy_call_window_fullscreen_toggle (window);
4027 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4029 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4031 if (priv->is_fullscreen)
4032 gtk_window_unfullscreen (GTK_WINDOW (window));
4034 gtk_window_fullscreen (GTK_WINDOW (window));
4038 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4039 GdkEventButton *event, EmpathyCallWindow *window)
4041 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4043 empathy_call_window_video_menu_popup (window, event->button);
4051 empathy_call_window_key_press_cb (GtkWidget *video_output,
4052 GdkEventKey *event, EmpathyCallWindow *window)
4054 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4056 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4058 /* Since we are in fullscreen mode, toggling will bring us back to
4060 empathy_call_window_fullscreen_toggle (window);
4068 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4069 GdkEventMotion *event, EmpathyCallWindow *window)
4071 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4073 if (priv->is_fullscreen)
4075 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4077 /* Show the bottom toolbar */
4078 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4085 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4089 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4091 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4093 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4094 button, gtk_get_current_event_time ());
4095 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4099 empathy_call_window_status_message (EmpathyCallWindow *self,
4102 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4106 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4108 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4110 return priv->ui_manager;
4113 EmpathyGstAudioSrc *
4114 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4116 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4118 return (EmpathyGstAudioSrc *) priv->audio_input;
4121 EmpathyGstVideoSrc *
4122 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4124 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4128 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4129 const gchar *device)
4131 EmpathyGstVideoSrc *video;
4134 /* Restart the camera only if it's already running */
4135 running = (self->priv->video_preview != NULL);
4136 video = empathy_call_window_get_video_src (self);
4139 empathy_call_window_play_camera (self, FALSE);
4141 empathy_video_src_change_device (video, device);
4144 empathy_call_window_play_camera (self, TRUE);